Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Player Dying

Asked by
Trewier 146
10 years ago

I want to update a value when a player dies, how would I do that?

2 answers

Log in to vote
3
Answered by
coo1o 227 Moderation Voter
10 years ago

NOTE: The code here is untested.

Use the Died event of humanoids.

workspace.Player.Humanoid.Died:connect(function()
print('Player died!')
end)

Then we just incorporate a value.

local dead = false

workspace.Player.Humanoid.Died:connect(function()
dead = true
end)

To make it work with anybody that joins the game, use PlayerAdded.

local dead = false

game.Players.PlayerAdded:conect(function(player)
repeat wait() until player.Character
player.Character.Humanoid.Died:connect(function()
dead = true
end)
end)

~coo1o

Ad
Log in to vote
0
Answered by 10 years ago

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.

2
It's not best to use CharacterRemoving for a script that only detects death because it runs ANY time the player's character is removed, say like when the player leaves. coo1o 227 — 10y

Answer this question