Humanoid.Died only running once

I’ve been working on a “don’t press the button” game for a while now and wanted to add dead messages today, but unfortunately the message only appears once in the chat.

Here is my Code:

--Death Message
game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Wait()
	plr.Character:WaitForChild("Humanoid").Died:Connect(function()
		MessagePlayer("all", plr.Name.." has died...",252, 0, 12,"SourceSansBold")
	end)
end)

Can you tell me why that does not work?
Btw I am a beginner so can you keep your explanations simple?
Thx (:

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:connect(function()
		local Human = plr.Character:WaitForChild("Humanoid") --Defines a new human every time the player spawns.
		Human.Died:connect(function()
			MessagePlayer("all", plr.Name.." has died...",252, 0, 12,"SourceSansBold")
		end)
	end)
end)
2 Likes

This work

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
		local humanoid = character:FindFirstChild("Humanoid")
		
		humanoid.Died:Connect(function(died)
			wait()
			MessagePlayer("all", plr.Name.." has died...",252, 0, 12,"SourceSansBold")
		end)
end)

You can have whatever’s in the PlayerAdded function to a new script in StarterCharacterScript and modify the names. This way, a new script will be created whenever your player respawns, as explained from HeyWhatsHisFace.

Of course, this is not optimized if you were to make for a lot of players.

For RBXScriptSignals :Wait() will only pause your script until it happens, then it will do everything after it.
On the other hand, :Connect() will run every time the event is fired, and in this case :Connect() should be used.
:Wait() can also be explained as a :Connect() function that instantly has :Disconnect() called on it after it was ran once.
Here’s the script that should fix it:

--Death Message
game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function()
		plr.Character:WaitForChild("Humanoid").Died:Connect(function()
			MessagePlayer("all", plr.Name.." has died...",252, 0, 12,"SourceSansBold")
		end)
	end)
end)