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

How do I make a script that adds one to a textbox everytime a player leaves?

I have this so far

Amount = script.parent.parent

script.Parent.Parent.Parent.Parent.Parent.Character:WaitForChild('Humanoid').Died:connect(function()

	Amount:WaitForChild('PE').Text = Amount:WaitForChild('PE').Text + 1

end)

It works fine the first time someone leaves, but then once a second player leaves it adds more then one.

1 answer

You need to make a variable that will be a constant counter for the players that have left. Also, you need to use the PlayerRemoving event of players to add one to the variable and update the text accordingly. What you were doing was using died, meaning whenever a player resets, it adds one to the text.

local Amount = script.Parent.Parent
local PlayersLeaving = 0

game:GetService("Players").PlayerLeaving:Connect(function()
	PlayersLeaving = PlayersLeaving + 1
    Amount:WaitForChild('PE').Text = PlayersLeaving
end)

1 comment

0

It still added wayyy more then one

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