Ragdoll on Low Health Not Working

Hey DevForums! I was working on a script for my game and stumbled across a problem. I want the character to ragdoll when the humanoid health less than or equal to 10. It seems to not work though and I can’t figure out why.

I’ve tried multiple things such as going to other posts and seeing if they had a somewhat similar problem. I made a few adjustments to script such as, instead of using RunService.Heartbeat, I used Humanoid.HealthChanged (although this doesn’t really change how the script works).

Note: For some reason it only works when the character dies!

Script:

local RunService = game:GetService("RunService");

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		Character:WaitForChild("Humanoid").HealthChanged:Connect(function()
			if (Character:WaitForChild("Humanoid").Health <= 10) and (Character) then
				for _, v in pairs(Character:GetDescendants()) do
					if v:IsA("Motor6D") then
						Character:WaitForChild("Humanoid").RequuiresNeck = false;
						
						local a0, a1 = Instance.new("Attachment"), Instance.new("Attachment")
						a0.CFrame = v.C0
						a1.CFrame = v.C1
						a0.Parent = v.Part0
						a1.Parent = v.Part1

						local b = Instance.new("BallSocketConstraint")
						b.Attachment0 = a0
						b.Attachment1 = a1
						b.Parent = v.Parent
						
						local Ragdolled = Instance.new("BoolValue", Character)
						Ragdolled.Name = "IsRagdoll"

						v.Enabled = false;
					end
				end
			end
			if (Character:WaitForChild("Humanoid").Health > 10) and (Character) then
				for _, v in pairs(Character:GetDescendants()) do
					if v:IsA("Attachment") then
						v:Destroy()
					end
					
					if v:IsA("BallSocketConstraint") then
						v:Destroy()
					end
					
					if v:IsA("Motor6D") then
						v.Enabled = true;
					end
				end
				
				if Character:FindFirstChild("IsRagdoll") then
					Character:WaitForChild("Humanoid").RequuiresNeck = true;
					Character:FindFirstChild("IsRagdoll"):Destroy()
				end
			end
		end)
	end)
end)
1 Like

I think it’s because of this line,

I think this makes it so it only runs when the CharacterAdded event runs, I’m not too sure though but that’s my first guess. I’m not very experienced with coding yet and have never tried anything like this so take my answer with a grain of salt.

OH

This might be why?

Try using

Humanoid:ChangeState("Ragdoll")

Also is this a custom ragdoll script made by you, or are you using a free model?

Nevermind I solved it. The problem was that I was testing it by myself and I changed the properties of my humanoid HP to a value under 10. However, this does not fire the HealthChanged event. So the script works fine and all, and this script is free to use for anyone who wants to use it!

1 Like

I made the script myself with a tiny bit of help of DevForum resources that I found.

Cool was asking in case maybe it had it’s own documentation but glad it worked out.