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

When a player dies or leaves the server how do you make a textbox change?

When a player types in to the textbox their class and the number decreases is what I have but how do I make it so if the person dies or disconnects the number goes back up?

1 answer

For death:

Every character has a humanoid, and humanoids has a .Died event. To check every character that has joined the game, you also need to check every player that gets in the game since your script is server script.

Here's PlayerAdded event of game.Players

Here's CharacterAdded event of Player

And Here's Died event of Humanoid

And here's an example

game.Players.PlayerAdded:connect(function(Player)
	Lives = 3
	Player.CharacterAdded:connect(function(Char)
		Char.Humanoid.Died:connect(function()
			Lives = Lives - 1
			if Lives == 0 then
				print("Game Over")
			end
		end
	end
end

For Leaving:

For this, we need to use game.Players' PlayerRemoving event.

And here's an example

game.Players.PlayerRemoving:connect(function(Player)
	print(Player.Name.." is leaving the server.")
end

Additional note: Keep in mind that putting wait(Time) after a PlayerRemoving event will cause an error if you try to work on that player since Server can't keep removed player's information that much.

1 comment

0

That kinda stuff looks exactly the same, but doesnt want to work...

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