All I need is the connection. That's what know:
function OnDied() end --Here goes the connection
The Died event is an event of Humanoids.
To get the Humanoid, it is usually done with anonymous functions, so we can "stack" our events. Remember that died events only run a single time; after the Humanoid dies once, the character will get a new Humanoid, thus making your previous connection invalid. Using the CharacterAdded event defeats this.
game.Players.PlayerAdded:connect(function(plr) plr.CharacterAdded:connect(function(chr) chr:WaitForChild("Humanoid").Died:connect(function() print(plr.Name.." died!") end) end) end)
There are likely ways to do this without anonymous functions, but they will probably be much messier.
Do you Mean this?
game.Players.PlayerAdded:connect(function(plr) plr.CharacterAdded:connect(function(chr) chr:WaitForChild("Humanoid").Died:connect(function() print(plr.Name.." died!") end) end) end)