Ragdoll On Death Isn't Working

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