I've made some code that keeps track of how many users are alive in the game, however, it always resets the alive users to 0 whenever it loops through the code again, so if there's one person in the game and they die, instead of it saying "0 players alive", it will say "-1 players alive", since instead of starting at the number 1 (1 player), it starts at 0.
function GivePlayersValue()
local p = game.Players:GetPlayers()
for i = 1, #p do
local s = Instance.new("StringValue", p[i])
s.Name = "Playing"
end
end
local numberAlive = 0
local stringtoConcat = " PLAYER(S) ALIVE"
function GetAlivePlayers()
local count = 0 --this line is the problem, as it resets the count to 0. I just don't know any alternative
local p = game.Players:GetPlayers()
for i = 1, #p do
if p[i]:FindFirstChild("Playing") then
count = count + 1
else
count = count - 1
end
end
return count
end
game.Players.PlayerAdded:connect(GivePlayersValue)
while true do
wait(1)
local combination = tonumber(GetAlivePlayers())
for i,v in pairs(game.Players:GetChildren()) do
v.PlayerGui.PAGui.Count.Text = combination .. stringtoConcat
end
end

2 comments
Works perfectly. Thanks!
No problem :)