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

How would I track a player's death?

Asked by
yurhomi10 192
9 years ago

Well, I wanna make a game where people will sword fight and then the match will end when either of them dies, the problem is how I would track their death without having to use a while loop considering it will lag people's games. Any ideas? I'm not requesting a script but a method that can help me with this. Thanks and much appreciated for the help!

2 answers

Log in to vote
1
Answered by
Discern 1007 Moderation Voter
9 years ago

Use the "Died" event. Here's a little "template" you can use.

NOTE: Died only works if the Humanoid is a descendant of Workspace.

function died()
--Insert Code Here. This will run every time "character" dies. "Character" is specified in line 5.
end

character.Humanoid.Died:connect(died) --Make sure this is connected to a character's Humanoid.

Click here for more information on the Died event.

Ad
Log in to vote
1
Answered by
RoboFrog 400 Moderation Voter
9 years ago

I'm going to assume this page will help you greatly.

game:GetService('Players').PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(character)
        character:WaitForChild("Humanoid").Died:connect(function()
            print(player.Name .. " has died!")
        end)
    end)
end)

Answer this question