How to make ragdolls

Hi, I’ve been looking into how I can make a ragdoll when a player dies. I even have a code on ragdoll which runs when the player dies, but when the player dies all the Motor6Ds are removed from the character and the code does not work. Here’s the code:

local Character = script.Parent;

Character.Humanoid.Died:Connect(function()
	local descendants = Character:GetDescendants()
	for i = 1, #descendants do
		local desc = descendants[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)
1 Like

I believe it’s because by default humanoids break joints on death, so you could just disable that and it should work.

3 Likes

Okay, thank you, I will try that!

It worked! Thank you so much! Literally thanks so much.

1 Like