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

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

Asked by 7 years ago
Edited 7 years ago

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

Log in to vote
0
Answered by
R_alatch 394 Moderation Voter
7 years ago

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)
0
It still added wayyy more then one carsheep -8 — 7y
Ad

Answer this question