Easiest way to make a ragdoll script?

Hi! The topic is quite self explanatory. I want to know the easiest way to make a character ragdoll. I have searched several posts but most don’t work. I also tried using an external module but it gets complicated and interferes with other things.

2 Likes

Place in StarterCharacter

--> LOCAL VARIABLES
local Humanoid = script.Parent:WaitForChild("Humanoid")

--> CODE
Humanoid .BreakJointsOnDeath = false

--> FUNCTIONS
Humanoid.Died:Connect(function()
	for index,joint in pairs(script.Parent:GetDescendants()) do
		if joint:IsA("Motor6D") then
			local socket = Instance.new("BallSocketConstraint")
			local a1 = Instance.new("Attachment")
			local a2 = Instance.new("Attachment")
			a1.Parent = joint.Part0
			a2.Parent = joint.Part1
			socket.Parent = joint.Parent
			socket.Attachment0 = a1
			socket.Attachment1 = a2
			a1.CFrame = joint.C0
			a2.CFrame = joint.C1
			socket.LimitsEnabled = true
			socket.TwistLimitsEnabled = true
			joint:Destroy()
		end
	end
end)
18 Likes
local Character = script.Parent
local Humanoid = Character:WaitForChild("Humanoid")
Humanoid.BreakJointsOnDeath = false

local function OnHumanoidDied()
	for _, Part in ipairs(Character:GetChildren()) do
		if Part:IsA("BasePart") then
			local Motor6D = Part:FindFirstChildWhichIsA("Motor6D")
			if Motor6D then
				if Part.Name ~= "Head" then
					local BallSocket = Instance.new("BallSocketConstraint")
					local Attachment1 = Instance.new("Attachment")
					local Attachment2 = Instance.new("Attachment")
					Attachment1.CFrame = Motor6D.C0
					Attachment2.CFrame = Motor6D.C1
					Attachment1.Parent = Motor6D.Part0
					Attachment2.Parent = Motor6D.Part1
					BallSocket.Attachment0 = Attachment1
					BallSocket.Attachment1 = Attachment2
					BallSocket.Parent = Motor6D.Parent
					Motor6D:Destroy()
				elseif Part.Name == "Head" then
					local WeldConstraint = Instance.new("WeldConstraint")
					WeldConstraint.Part0 = Motor6D.Part0
					WeldConstraint.Part1 = Motor6D.Part1
					WeldConstraint.Parent = Motor6D.Parent
				end
			end
		end
	end
end

Humanoid.Died:Connect(OnHumanoidDied)

Just a slight improvement with the head fixed.

7 Likes

I’d recommend :Once() instead of :Connect() in this case.

4 Likes

Not a good recommendation since Once() only fires the signal once, we want this listener to run whenever the humanoid dies so it can work more then one time.

I love bumping old threads

also, every time a player respawns, Player.Character will always have a different Humanoid than last time, so you cannot re-use the same Humanoid including the Connect function

5 Likes