Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Fall Damage With Ragdoll Works, But Glitch why?

Asked by
Zero_Tsou 175
4 years ago
Edited 4 years ago

So uh I made a fall damage script with a ragdoll, ( you can copy this script and paste it in a server script and try it urself)

NOTE: This is my first time using the ragdoll system ( BallSocketConstraint )

ServerScript:

game.Players.PlayerAdded:Connect(function(plr)

    plr.CharacterAdded:Connect(function(char)
    local humanoid = char:WaitForChild("Humanoid")
    local Root = char.HumanoidRootPart
    local OriginalPos
    humanoid.StateChanged:Connect(function(oldstate, newstate)
        if not Root then return end

        if newstate == Enum.HumanoidStateType.Freefall then
            OriginalPos = Root.Position.Y
            if not OriginalPos then return end

        elseif newstate == Enum.HumanoidStateType.Landed then
                local LandPos = Root.Position.Y
            if not LandPos then return end

            if OriginalPos < LandPos then return end
            humanoid:TakeDamage(OriginalPos - LandPos)
           local d = char:GetDescendants()
        for i=1,#d do
        local desc = d[i]
        if desc:IsA("Motor6D") then
            local socket = Instance.new("BallSocketConstraint")
            local part0 = desc.Part0
            local joint_name = desc.Name
            local attachment0 = desc.Parent:FindFirstChild(joint_name.."Attachment") or desc.Parent:FindFirstChild(joint_name.."RigAttachment")
            local attachment1 = part0:FindFirstChild(joint_name.."Attachment") or part0:FindFirstChild(joint_name.."RigAttachment")
            if attachment0 and attachment1 then
                socket.Attachment0, socket.Attachment1 = attachment0, attachment1
                socket.Parent = desc.Parent
                desc:Destroy()
            end 
        end
    end


end
end)
    end)
        end)

The ragdoll works but, it sends me flying up in the air and glitching me, why? tell me if it doesn't glitch for u

Answer this question