Hello, this ragdoll script is supposed to make the character’s limbs move freely when low health or dead.
For some reason, the script causes the player to take forever to respawn. The exact issue is that the player starts ragdolling, but keeps regenning for some reason as if they are alive, until about 10 seconds later when the character actually die dies (health gets set to zero and respawns a few seconds later).
This code is being run on the server, and from the server’s perspective, it still looks like what’s happening on the client. I’m not really sure why this causes the delay in death, but it’s definently the source of the problem as removing it fixes the issue. Here is a video of the issue:
And here is the code:
local humanoid = script.Parent:WaitForChild("Humanoid")
humanoid.BreakJointsOnDeath = false
local character = script.Parent
local player = game.Players:GetPlayerFromCharacter(character)
local torso = character:WaitForChild("Torso")
local hrp = character:WaitForChild("HumanoidRootPart")
local animatescript = character:WaitForChild("Animate")
local recentlyStartedRagdolling = false
local ragdollhealth = 20
--------------------------------------------------
script.Ragdolling.Changed:Connect(function()
if script.Ragdolling.Value == true then
recentlyStartedRagdolling = true
print("Starting " .. character.Name .. "'s ragdoll")
humanoid:ChangeState(Enum.HumanoidStateType.Physics)
humanoid.PlatformStand = true
animatescript.Disabled = true
player.PlayerGui.Dash.SlideDisabled.Value = true
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.Enabled = false
end
end
task.wait(2)
recentlyStartedRagdolling = false
elseif script.Ragdolling.Value == false then
recentlyStartedRagdolling = false
if humanoid.Health < ragdollhealth then script.Ragdolling.Value = true return end
humanoid:ChangeState(Enum.HumanoidStateType.Running)
animatescript.Disabled = false
humanoid.PlatformStand = false
player.PlayerGui.Dash.SlideDisabled.Value = false
print("Stopping " .. character.Name .. "'s ragdoll")
for index,joint in pairs(script.Parent:GetDescendants()) do
if joint:IsA("BallSocketConstraint") then
joint:Destroy()
end
end
for i, m6d in pairs(character:GetDescendants()) do
if m6d:IsA("Motor6D") then
if m6d.Name == 'RootJoint' then
m6d.Parent = hrp
m6d.Enabled = true
else
m6d.Parent = humanoid.Parent.Torso
m6d.Enabled = true
end
end
end
end
end)
humanoid.Changed:Connect(function(Changed)
if Changed == 'Health' then
if humanoid.Health < ragdollhealth then
script.Ragdolling.Value = true
elseif not recentlyStartedRagdolling then
script.Ragdolling.Value = false
end
end
end)
humanoid.Died:Connect(function()
script.Ragdolling.Value = true
end)
Any help would be much appreciated!