https://pastein.ru/t/47Y

  скопируйте уникальную ссылку для отправки

Загрузка данных


-- PlayerRagdollHandler.lua (в StarterPlayerScripts - LocalScript)

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")

local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")

local RagdollRemote = ReplicatedStorage:WaitForChild("RagdollEvent") -- RemoteEvent для синхронизации Ragdoll

local isRagdolled = false
local currentMotor6Ds = {}
local currentRigidConstraints = {}

local function createRigidConstraints()
    for _, joint in pairs(Humanoid:GetChildren()) do
        if joint:IsA("Motor6D") then
            local p0, p1 = joint.Part0, joint.Part1
            if p0 and p1 then
                table.insert(currentMotor6Ds, joint)
                local rigid = Instance.new("NoCollisionConstraint") -- Используем NoCollisionConstraint для простоты
                rigid.Part0 = p0
                rigid.Part1 = p1
                rigid.Parent = p0 -- Или куда угодно
                table.insert(currentRigidConstraints, rigid)
                joint.Enabled = false -- Отключаем Motor6D
            end
        end
    end
end

local function destroyRigidConstraints()
    for _, rigid in ipairs(currentRigidConstraints) do
        rigid:Destroy()
    end
    currentRigidConstraints = {}
    for _, motor in ipairs(currentMotor6Ds) do
        motor.Enabled = true -- Включаем Motor6D обратно
    end
    currentMotor6Ds = {}
end

local function toggleRagdoll(duration)
    if isRagdolled then return end -- Избегаем повторной активации

    isRagdolled = true
    Humanoid.RequiresNeck = false -- Отключаем автоматическую ориентацию головы
    Humanoid.PlatformStand = true

    -- Это клиентская часть визуализации ragdoll.
    -- Сервер все еще должен обрабатывать столкновения и логику.
    for _, part in ipairs(Character:GetChildren()) do
        if part:IsA("BasePart") and part ~= Humanoid.RootPart then
            part.CanCollide = true
        end
    end

    createRigidConstraints() -- Создаем constraints

    task.wait(duration) -- Ждем время ragdoll

    -- Восстанавливаемся
    destroyRigidConstraints() -- Удаляем constraints

    Humanoid.RequiresNeck = true
    Humanoid.PlatformStand = false

    for _, part in ipairs(Character:GetChildren()) do
        if part:IsA("BasePart") and part ~= Humanoid.RootPart then
            -- Восстанавливаем коллизии, если они были изменены
            -- part.CanCollide = false
        end
    end

    isRagdolled = false
end

-- Слушаем событие с сервера для активации Ragdoll
RagdollRemote.OnClientEvent:Connect(function(duration)
    toggleRagdoll(duration)
end)

-- Создаем RemoteEvent для Ragdoll (для сервера) в ReplicatedStorage, если его нет
-- (Это должно быть создано на сервере, но здесь для примера, чтобы не было ошибок)
local ragdollEvent = ReplicatedStorage:FindFirstChild("RagdollEvent")
if not ragdollEvent then
    ragdollEvent = Instance.new("RemoteEvent")
    ragdollEvent.Name = "RagdollEvent"
    ragdollEvent.Parent = ReplicatedStorage
end