Ragdoll causes player to fly upwards, need help

I am currently scripting a ragdoll script using help from the DevForum, but now I am kinda stuck. As you can see with the image below, the ragdoll sometimes likes to make the player fly up and it only happens ~40% of the time. Of course, I looked around for soultions, tried some, but they didn’t work. If anybody knows a solution, please help. My code is below(Ragdoll module).

image

local RAGDOLL = {}

function RAGDOLL:RagdollFromPlayer(player: Player)
    local character = player.Character or player.CharacterAdded:Wait()
    local HUMANOID = character:FindFirstChildWhichIsA('Humanoid')
    local HUMANOID_ROOT_PART = character:FindFirstChild('HumanoidRootPart')

    HUMANOID.JumpPower = 0
    HUMANOID.BreakJointsOnDeath = false
    HUMANOID:ChangeState(Enum.HumanoidStateType.Physics)
    HUMANOID_ROOT_PART:SetNetworkOwner(nil)

    for _, motor6D in pairs(character:GetDescendants()) do
        if motor6D:IsA('Motor6D') then
            motor6D.Enabled = false
            local A_0, A_1 = Instance.new('Attachment'), Instance.new('Attachment')
            A_0.CFrame = motor6D.C0
            A_1.CFrame = motor6D.C1

            local BALL_SOCKET_CONSTRAINT = Instance.new('BallSocketConstraint')
            BALL_SOCKET_CONSTRAINT.Attachment0 = A_0
            BALL_SOCKET_CONSTRAINT.Attachment1 = A_1

            A_0.Name = 'RagdollAttachment0'
            A_1.Name = 'RagdollAttachment1'
            BALL_SOCKET_CONSTRAINT.Name = 'RagdollConstraint'

            A_0.Parent = motor6D.Part0
            A_1.Parent = motor6D.Part1
            BALL_SOCKET_CONSTRAINT.Parent = motor6D.Part0

        end
    end
end


function RAGDOLL:Unragdoll(player: Player)
    local character = player.Character or player.CharacterAdded:Wait()
    local HUMANOID = character:FindFirstChildWhichIsA('Humanoid')
    local HUMANOID_ROOT_PART = character:FindFirstChild('HumanoidRootPart')

    HUMANOID.JumpPower = 50
    HUMANOID.BreakJointsOnDeath = true
    HUMANOID:ChangeState(Enum.HumanoidStateType.None)
    HUMANOID_ROOT_PART:SetNetworkOwnershipAuto()

    for _, instance in pairs(character:GetDescendants()) do
        if instance.Name:find('Ragdoll') then
            instance:Destroy()
        elseif instance:IsA('Motor6D') then
            instance.Enabled = true
        end
    end
end



return RAGDOLL

If you know a solution, please reply below.

PS: The module is only being ran on the server, but idk if that will cause anything because of SetNetworkOwner(nil).

2 Likes