Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How would I track a player's death?

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

✓ Accepted answer

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.

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.