Death is delayed

I am trying to make a ragdoll. When I made my ragdoll and reset it took a few seconds for me to ragdoll and actually die. Everything else in the background isn’t lagging just the death. Sometime it doesn’t delay the death.

Here is a video of it occuring.

I’m not sure if it is my ragdoll script or not. If you have any idea what it could be please tell me thx.
Here is my ragdoll script.

local debris = game:GetService("Debris")

local function Ragdoll(character)
	local humanoid = character:FindFirstChild("Humanoid")
	local root = character:FindFirstChild("HumanoidRootPart")
	if humanoid and root then
		if humanoid.Health<1 then
			humanoid.Health = 0
			humanoid:ChangeState(Enum.HumanoidStateType.Physics)
			humanoid.PlatformStand = true
			
			local force = Instance.new("BodyVelocity")
			force.MaxForce = Vector3.new(1,0,1) * 10000
			force.Velocity = root.CFrame.LookVector * -50
			force.Parent = root

			for i, v in pairs(character:GetDescendants()) do
				if v:IsA("Motor6D") then
					local at0 = Instance.new("Attachment", v.Part0)
					local at1 = Instance.new("Attachment", v.Part1)
					at0.CFrame = v.C0
					at1.CFrame = v.C1

					local con = Instance.new("RopeConstraint", v.Part0)
					con.Name=v.Name
					con.Length = 0.1
					con.Attachment0 = at0
					con.Attachment1 = at1

					v:Destroy()
				end
			end

			debris:AddItem(force, 0.1)
		end
	end
end

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		local h = char:WaitForChild("Humanoid")
		h.BreakJointsOnDeath = false
		h.Died:Connect(function() Ragdoll(char) end)
	end)
end)

BreakJointsOnDeath set to false has an issue where the server doesnt detect that you died until some time passed or you went into first person camera.

A temporary solution would be to just detect death on the client, and fire a remote to the server that actually makes the ragdoll

2 Likes

Still happens. Maybe I did something wrong.
Could I just do a Humanoid:GetPropertyChangedSignal on the HP?

local debris = game:GetService("Debris")

game:GetService("Players").PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		character:WaitForChild("Humanoid").BreakJointsOnDeath = false
	end)
end)

game:GetService("ReplicatedStorage").Events.Ragdoll.OnServerEvent:Connect(function(player)
	local character = player.Character
	local humanoid = character:WaitForChild("Humanoid")
	local root = character:WaitForChild("HumanoidRootPart")

	humanoid.Died:Connect(function()
		if humanoid and root then
			if humanoid.Health<1 then
				humanoid.Health = 0
				humanoid:ChangeState(Enum.HumanoidStateType.Physics)
				humanoid.PlatformStand = true

				local force = Instance.new("BodyVelocity")
				force.MaxForce = Vector3.new(1,0,1) * 10000
				force.Velocity = root.CFrame.LookVector * -50
				force.Parent = root

				for i, v in pairs(character:GetDescendants()) do
					if v:IsA("Motor6D") then
						local at0 = Instance.new("Attachment", v.Part0)
						local at1 = Instance.new("Attachment", v.Part1)
						at0.CFrame = v.C0
						at1.CFrame = v.C1

						local con = Instance.new("RopeConstraint", v.Part0)
						con.Name=v.Name
						con.Length = 0.1
						con.Attachment0 = at0
						con.Attachment1 = at1

						v:Destroy()
					end
				end

				debris:AddItem(force, 0.1)
			end
		end
	end)
end)

Get rid of the humanoid.Died connection in the event. Should probably also remove if humanoid.Health<1 then

Like this:

local debris = game:GetService("Debris")

game:GetService("Players").PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		character:WaitForChild("Humanoid").BreakJointsOnDeath = false
	end)
end)

game:GetService("ReplicatedStorage").Events.Ragdoll.OnServerEvent:Connect(function(player)
	local character = player.Character
	local humanoid = character:WaitForChild("Humanoid")
	local root = character:WaitForChild("HumanoidRootPart")

	if humanoid and root then
		humanoid.Health = 0
		humanoid:ChangeState(Enum.HumanoidStateType.Physics)
		humanoid.PlatformStand = true

		local force = Instance.new("BodyVelocity")
		force.MaxForce = Vector3.new(1,0,1) * 10000
		force.Velocity = root.CFrame.LookVector * -50
		force.Parent = root

		for i, v in pairs(character:GetDescendants()) do
			if v:IsA("Motor6D") then
				local at0 = Instance.new("Attachment", v.Part0)
				local at1 = Instance.new("Attachment", v.Part1)
				at0.CFrame = v.C0
				at1.CFrame = v.C1

				local con = Instance.new("RopeConstraint", v.Part0)
				con.Name=v.Name
				con.Length = 0.1
				con.Attachment0 = at0
				con.Attachment1 = at1

				v:Destroy()
			end
		end

		debris:AddItem(force, 0.1)
	end
end)
3 Likes

to detect on local script just

make a local script in startercharacter

local char = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
char:WaitForChild(“Humanoid”).Died:Connect(function()
–fire remote event here
game.ReplicatedStorage:WaitForChild(“Events”):WaitForChild(“Ragdoll”):WaitForChild(“Die”):Fire(char)
end)