All I need is the connection. That's what know:
function OnDied()
end
--Here goes the connection
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)
what is the 'Charcter' variable?
I would appreciate if accept my Answer if I helped you with your Problem.
The Character is not another name for the Player. The character is the 3-d object running around on your computer screen in game.Workspace, while the player does pretty much everything else. The player is located in game.Players.
This discussion is preserved as it was. New answers, comments, and votes are closed.
4 comments
How do you mean we can "'stack' our events?" Can you please explain that?
If you look at how his code is structured, there are three events nested inside each other. By using anonymous function, the scripter can more easilly write such a convuluted structure, as it's a lot easier to mentally keep track of where everything is. It also allows for the inner functions to inherit the environment of the outer functions.
^
Thanks a lot it worked!