Humanoid.Died not working properly

For some reason when I try to die, it won’t fire the event until line 51 but at that point, it will give me just the print(character added). If someone knows why plz tell me.

https://i.gyazo.com/d454fce9c135a16b9a96a8ae68c9dd1f.mp4

https://i.gyazo.com/ce9e5953434c5686930345062befb4f7.mp4 – this one only gives me the “character added” after line 51.

Can you please post your code so we can see what the problem is

Would you please provide the code that you are using. You don’t have to screenshot it, just copy and paste the code and use ``` to format it.

1 Like

Should’ve provided that in your OP

Oops.

local ServerStorage = game:GetService("ServerStorage")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Map = ReplicatedStorage:WaitForChild("Map")
local Status = ReplicatedStorage:WaitForChild("Status")

local Died
game.Players.PlayerAdded:Connect(function(player)
	
	Died = Instance.new("BoolValue")
	Died.Value = false
	Died.Parent = player
	
	if #game.Players:GetPlayers() >= 1 then Intermission() else Status.Value = "Wait for 2 or more players" end
	
	player.CharacterAdded:Connect(function(character)
		print("character added")
		character.Humanoid.Died:Connect(function()
			for _,Plr in pairs(game.Players:GetPlayers()) do
				if player.Name == Plr.Name then
					Died.Value = true
					print(Plr)
				end
				
			end
			
			
		end)
	end)

end)


function Intermission()
	local t = 15
	
	repeat
		t = t - 1
		wait()
		print(t)
		Status.Value = "Intermission in "..t
	until t == 1
	
	Status.Value = "Beginning game!!"
	wait(3)
	
	Map:Clone().Parent = workspace
	wait(1)
	for i, Plr in pairs(game.Players:GetPlayers()) do
		
		Plr.Character.HumanoidRootPart.CFrame = CFrame.new(workspace.Map.Position + Vector3.new(0,5,0))
		print(Plr)
		
		
	end
	
	
	
	
	
end

```
lol is this a code block
```
and my answer is

local RunService = game:GetService('RunService')

function Died(Humanoid, Callback)
  return Humanoid:GetPropertyChangedSignal('Health'):Connect(function()
    local Health = Humanoid.Health
    if (Health < 1) then Callback(Health) end
  end)
end

Well yes, you aren’t listening to when the Character is added before it actually gets added so of course the script doesn’t work.

ok? So how do I fix this problem?

Put it before the check for enough players (I’ll link just the adjusted section).

game.Players.PlayerAdded:Connect(function(player)
	
	Died = Instance.new("BoolValue")
	Died.Value = false
	Died.Parent = player

player.CharacterAdded:Connect(function(character)
		print("character added")
		character.Humanoid.Died:Connect(function()
			for _,Plr in pairs(game.Players:GetPlayers()) do
				if player.Name == Plr.Name then
					Died.Value = true
					print(Plr)
				end
			end
		end)
	end)
	
	if #game.Players:GetPlayers() >= 1 then Intermission() else Status.Value = "Wait for 2 or more players" end
	

end)

Intermission() has to complete before the line after it is executed, so it has to complete the count down before CharacterAdded is bound. You can call it in a separate coroutine to allow the CharacterAdded bind line to execute when Intermission yields (via wait)

if #game.Players:GetPlayers() >= 2 then -- also pretty sure you want this to run when there's 2 or more players, not 1 or more players.
    spawn(function() -- spawn(function) is a roblox global that offers a shorthand syntax for creating then resuming a coroutine.
        Intermission()
    end)
else 
    Status.Value = "Wait for 2 or more players"
end

player.CharacterAdded:Connect(function(character)
    print("character added")
end)

check out coroutines for a more in depth explanation on what’s going on behind the scenes.

Hi.
I’ve had issues with Humanoid.Died recently too and I realized that the Died event is quite unstable when replacing the StarterCharacter with a custom rig. It does work on client, but the call may be delayed by up to an entire minute on the server sometimes, making it unreliable.

As such, I’ve opted to making my own death notifier which, even if it adds additional delays, lets the player notify the server itself that this player died. Not the best way, clearly not the most secure, but it does work reliably.
Additionally, you could keep track of the player’s health server-sidedly and whenever it reaches <= 0, assume the player died.

1 Like

I found a way to reliably reproduce Humanoid.Died not firing on the server.

  1. Server attaches a Humanoid.Died handler
  2. Humanoid Root Part’s network owner is the client. When I used SetNetworkOwner(nil) on the HRP then my Server Died handler was fired
  3. Server sets Humanoid.Health to 0
  4. Client receives Humanoid.Died
  5. It was here that the client was setting the HRP to Anchored. This seems to also be a key contributor to the Server not receiving the Humanoid.Died callback.

My solution was to anchor the HRP on the Server Died handler instead of the client Died handler.

1 Like