Ragdoll On Death Isn't Working

I don’t know, I just copy the code, I guess it gets sometimes.

1 Like

Doesn’t Seem like it worked, same thing, No Errors in output. Do you think I should make the Parent of the script StarterCharacterScripts or keep it as ServerScriptService?

When I tried it without correcting it, I got these errors:
image
image

So if it still doesn’t work there must be something slowing it down, you could also put this in StarterCharacterScripts, it works the same.

script.Parent:WaitForChild("Humanoid").BreakJointsOnDeath = false
script.Parent.Humanoid.Died:Connect(function()
	for _, v in pairs(script.Parent:GetDescendants()) do
		if v:IsA("Motor6D") then
			local Att0, Att1 = Instance.new("Attachment"), Instance.new("Attachment")
			Att0.CFrame = v.C0
			Att1.CFrame = v.C1
			Att0.Parent = v.Part0
			Att1.Parent = v.Part1
			local BSC = Instance.new("BallSocketConstraint")
			BSC.Attachment0 = Att0
			BSC.Attachment1 = Att1
			BSC.Parent = v.Part0

			v:Destroy()
		end
	end
	script.Parent.HumanoidRootPart.CanCollide = false
end)

lol, because it turns red? xd

Personally I prefer StarterCharacterScripts, it is more reliable.

2 Likes

I think the errors are just spelling mistakes.
getdescendants and attachments are spelled wrong
Here’s what worked for me:

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Char)
		Char:WaitForChild("Humanoid").BreakJointsOnDeath = false
		Char.Humanoid.Died:Connect(function()
			for _, v in pairs(Char:GetDescendants()) do
				if v:IsA("Motor6D") then
					local Att0, Att1 = Instance.new("Attachment"), Instance.new("Attachment")
					Att0.CFrame = v.C0
					Att1.CFrame = v.C1
					Att0.Parent = v.Part0
					Att1.Parent = v.Part1
					local BSC = Instance.new("BallSocketConstraint")
					BSC.Attachment0 = Att0
					BSC.Attachment1 = Att1
					BSC.Parent = v.Part0

					v:Destroy()
				end
			end
			Char.HumanoidRootPart.CanCollide = false
		end)
	end)
end)
7 Likes

Didn’t work, I put it inside of StarterCharacterScript and made it a Regular script and not a local

Didn’t work, I put it inside of StarterCharacterScripts and made it a Regular script and not a local

Nothing appears in the output? Is there something delaying the script? It is activated?
You could put print in and out of the function.

1 Like

yes,
no,
yes,
when I made it so it would print if the player died and ragdolled nothing came in the output.

local humanoid = script.Parent:WaitForChild('Humanoid')

humanoid.BreakJointsOnDeath = false

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()
			print("Player Has Died and Ragdoll Was Succsesful!")
		end
	end
end)

In the script you showed me then it would look like this,

script.Parent:WaitForChild("Humanoid").BreakJointsOnDeath = false
script.Parent.Humanoid.Died:Connect(function()
	for _, v in pairs(script.Parent:GetDescendants()) do
		if v:IsA("Motor6D") then
			local Att0, Att1 = Instance.new("Attachment"), Instance.new("Attachment")
			Att0.CFrame = v.C0
			Att1.CFrame = v.C1
			Att0.Parent = v.Part0
			Att1.Parent = v.Part1
			local BSC = Instance.new("BallSocketConstraint")
			BSC.Attachment0 = Att0
			BSC.Attachment1 = Att1
			BSC.Parent = v.Part0

			v:Destroy()
			print("Player Has Died and Ragdoll Was Succsesful!")
		end
	end
	script.Parent.HumanoidRootPart.CanCollide = false
end)

I also tried to fire this but nothing comes in the output and it doesnt work.

Look at this map and compare, there is only the baseplate, a spawnlocation and the script.
Ragdoll On Death.rbxl (28,5 KB)

1 Like

the one I made should be somewhere in the workspace or serverscriptstorate, but not inside the character

1 Like

Also this is for R6 Rigs to ragdoll, not R15

ServerScript or LocalScript?


nvm when I made it a server script, it worked!

Since the game despawns the character model when the player respawns, I simply make the ragdoll script move everything inside the character into another model. The game will despawn the character model (which is now empty), and the new model will persist. You might have to fix the camera in certain cases but this is my go to method for making them persist.

1 Like

From experience, as long as you also transfer the Humanoid over, the clothing should render as well. If you only transfer the baseparts and the shirt, the game wont think it’s a valid person to apply clothing to, so you need to also move the humanoid over.

1 Like

Yea but when I do that, the body floats up for some reason (when i mentioned having to change up stuff, i had to clone a new humanoid to remove the float, but clothing would not work), recently found a half fix, but after player respawns, the body returns to a stand up stance ( all stiff, without animation) when you step close to the ragdoll’d body

heres a link to the post (I will also post on the link as well, with video and my code:

Ultimately If I can’t figure out how to remove the glitches that go along side making the ragdoll persist, im just settle with letting it despawn on character respawn.

It turns out, since we are using a technique that requires breakjointsondeath to be false, when we reparent the humanoid, it tries to repair the joints we just destroyed. Therefore to fix this, just set breakjointsondeath to true before we reparent the character.

Heres what worked for me in a blank baseplate:

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Char)
		Char:WaitForChild("Humanoid").BreakJointsOnDeath = false
		Char.Humanoid.Died:Connect(function()
			local m = Instance.new("Model")
			m.Parent = game.Workspace
			for _, v in pairs(Char:GetDescendants()) do
				if v:IsA("Motor6D") then
					local Att0, Att1 = Instance.new("Attachment"), Instance.new("Attachment")
					Att0.CFrame = v.C0
					Att1.CFrame = v.C1
					Att0.Parent = v.Part0
					Att1.Parent = v.Part1
					local BSC = Instance.new("BallSocketConstraint")
					BSC.Attachment0 = Att0
					BSC.Attachment1 = Att1
					BSC.Parent = v.Part0

					v:Destroy()
				end
			end
			local g = Char:GetChildren()
			Char.Humanoid.BreakJointsOnDeath = true
			Char.HumanoidRootPart.CanCollide = false
			for i = 1,#g do
				g[i].Parent = m
			end
		end)
	end)
end)
1 Like

Works for the most part, the only thing that I would’ve liked to keep was the hats on the character (when breaking joints, the hats fall off the character to oblivion) but this is better than having a not-clothing character. Plus I do not see any glitches on my end.

edit: penguin’s post bellow is :100: give him :heart:

Ok so to fix that, we can simply weld all hat attachments. However, since the humanoid will break weld constraints, we are going to leave the humanoid at BreakJointsOnDeath to be false. Another big discovery I made is the fact that if you disable the original joint (The one the humanoid keeps replacing when BreakJointsOnDeath is false), the humanoid will not replace it, and it will act as if the joint is broken. I also added limits to the Head joint so that it doesn’t clip into the torso and look silly. Thus, I rearranged the code to do this now:

-set BreakJointsOnDeath to false
-put all parts of the character to another model
-replace joints with ballsocketconstraints
-disable original joint to prevent humanoid from replacing them
-replace accessorywelds with weldconstraints
-disable original accessoryweld to prevent humanoid from replacing them
-add limits to head socket joint
-win

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Char)
		Char:WaitForChild("Humanoid").BreakJointsOnDeath = false
		Char.Humanoid.Died:Connect(function()
			local m = Instance.new("Model")
			m.Parent = game.Workspace
			
			local g = Char:GetChildren()
			Char.HumanoidRootPart.CanCollide = false
			for i = 1,#g do
				g[i].Parent = m
			end

			for _, v in pairs(m:GetDescendants()) do
				if v:IsA("BasePart") then
					v:SetNetworkOwner(Player)
				end
				if v:IsA("Motor6D") then
					local Att0, Att1 = Instance.new("Attachment"), Instance.new("Attachment")
					Att0.CFrame = v.C0
					Att1.CFrame = v.C1
					Att0.Parent = v.Part0
					Att1.Parent = v.Part1
					local BSC = Instance.new("BallSocketConstraint")
					BSC.Attachment0 = Att0
					BSC.Attachment1 = Att1
					BSC.Parent = v.Part0
					if v.Part1.Name ==  "Head" then
						BSC.LimitsEnabled = true
						BSC.TwistLimitsEnabled = true
					end
					v.Enabled = false
				end
				if v.Name == "AccessoryWeld" then
					local WC = Instance.new("WeldConstraint")
					WC.Part0 = v.Part0
					WC.Part1 = v.Part1
					WC.Parent = v.Parent
					v.Enabled = false
				end
				if v.Name == "Head" then
					v.CanCollide = true
				end
			end
		end)
	end)
end)

– update: I also set the network ownership of the character’s parts to the player, as they seem to go back to the server when the player dies. Doing this prevents a noticeable lag spike when the player dies as the network ownership shifts to the server.

9 Likes