[SOLVED] Why does this ragdoll script delay and stop characters from respawning?

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!

3 Likes

If you want to respawn your character after a certain amount of time player:LoadCharacter() should work.

1 Like

The player should respawn after a set amount of time automatically. I don’t want to have to manually control their respawning, I want to know why they are even taking a long time to respawn in the first place.

1 Like

I figured out the problem myself. Using ChangeState seems to have been overwriting the state you recieve when you die, making the game not officially consider you dead and therefore not respawning you.

5 Likes

what did you do to fix it?

characters

I got rid of this line:

humanoid:ChangeState(Enum.HumanoidStateType.Physics)

It would overwrite the state that the humanoid needs to be considered actually dead.

1 Like

How did you get the character to plop to the ground then, and make them not able to move? bc that’s what the physics state achieves

Using humanoid.PlatformStand = true

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.