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)