I want to update a value when a player dies, how would I do that?
NOTE: The code here is untested.
Use the Died
event of humanoids.
1 | workspace.Player.Humanoid.Died:connect( function () |
2 | print ( 'Player died!' ) |
3 | end ) |
Then we just incorporate a value.
1 | local dead = false |
2 |
3 | workspace.Player.Humanoid.Died:connect( function () |
4 | dead = true |
5 | end ) |
To make it work with anybody that joins the game, use PlayerAdded
.
1 | local dead = false |
2 |
3 | game.Players.PlayerAdded:conect( function (player) |
4 | repeat wait() until player.Character |
5 | player.Character.Humanoid.Died:connect( function () |
6 | dead = true |
7 | end ) |
8 | end ) |
~coo1o
LocalPlayer.CharacterRemoving
That's an event that fires after the LocalPlayer
dies. It would help to distinguish player death from player left within your script.