Ragdoll Script Not Working Properly

Hello So I have this ragdoll script which is not working the way I want it to,some times it works, but then somestimes the avatar just stays still for awhile in this position before ragdolling. image
Here is the script

local Humanoid = script.Parent:WaitForChild("Humanoid")
Humanoid.BreakJointsOnDeath = false

Humanoid.Died:Connect(function()
   Humanoid:SetStateEnabled(Enum.HumanoidStateType.Ragdoll, false)
   for i,v in pairs(script.Parent.RightUpperLeg:GetDescendants()) do
   	if v:IsA("Motor6D") then
   		local BallConstraint = Instance.new("BallSocketConstraint")
   		local Attachment1 = Instance.new("Attachment")
   		local Attachment2 = Instance.new("Attachment")
   		Attachment1.Parent = v.Part0
   		Attachment2.Parent = v.Part1
   		BallConstraint.Parent = v.Parent
   		BallConstraint.Attachment0 = Attachment1
   		BallConstraint.Attachment1 = Attachment2
   		Attachment1.CFrame = v.C0
   		Attachment2.CFrame = v.C1
   		BallConstraint.LimitsEnabled = true
   		BallConstraint.TwistLimitsEnabled = true
   		v:Destroy()
   	end
   end
   for i,v in pairs(script.Parent.LeftUpperLeg:GetDescendants()) do
   	if v:IsA("Motor6D") then
   		local BallConstraint = Instance.new("BallSocketConstraint")
   		local Attachment1 = Instance.new("Attachment")
   		local Attachment2 = Instance.new("Attachment")
   		Attachment1.Parent = v.Part0
   		Attachment2.Parent = v.Part1
   		BallConstraint.Parent = v.Parent
   		BallConstraint.Attachment0 = Attachment1
   		BallConstraint.Attachment1 = Attachment2
   		Attachment1.CFrame = v.C0
   		Attachment2.CFrame = v.C1
   		BallConstraint.LimitsEnabled = true
   		BallConstraint.TwistLimitsEnabled = true
   		v:Destroy()
   	end
   end
   for i,v in pairs(script.Parent.LeftLowerLeg:GetDescendants()) do
   	if v:IsA("Motor6D") then
   		local BallConstraint = Instance.new("BallSocketConstraint")
   		local Attachment1 = Instance.new("Attachment")
   		local Attachment2 = Instance.new("Attachment")
   		Attachment1.Parent = v.Part0
   		Attachment2.Parent = v.Part1
   		BallConstraint.Parent = v.Parent
   		BallConstraint.Attachment0 = Attachment1
   		BallConstraint.Attachment1 = Attachment2
   		Attachment1.CFrame = v.C0
   		Attachment2.CFrame = v.C1
   		BallConstraint.LimitsEnabled = true
   		BallConstraint.TwistLimitsEnabled = true
   		v:Destroy() 
   	end
   end
   for i,v in pairs(script.Parent.RightLowerLeg:GetDescendants()) do
   	if v:IsA("Motor6D") then
   		local BallConstraint = Instance.new("BallSocketConstraint")
   		local Attachment1 = Instance.new("Attachment")
   		local Attachment2 = Instance.new("Attachment")
   		Attachment1.Parent = v.Part0
   		Attachment2.Parent = v.Part1
   		BallConstraint.Parent = v.Parent
   		BallConstraint.Attachment0 = Attachment1
   		BallConstraint.Attachment1 = Attachment2
   		Attachment1.CFrame = v.C0
   		Attachment2.CFrame = v.C1
   		BallConstraint.LimitsEnabled = true
   		BallConstraint.TwistLimitsEnabled = true
   		v:Destroy()
   	end
   end
end)

How do I fix this?

Maybe it can be because there is no force applied to the character and it stays where it is so maybe try adding a little force towards the character and see if it falls because I cant really see an error in the script right now

Seemed to work, thank you for the solution, answer marked as solution!

1 Like