I have a value names PlayerCount, when a PLAYER joins or leaves I want it to add and subtract the PlayerCount value.
When I look at the PlayerCount value in Play Solo, it is right (PlayerCount.Value == 1). However when I add an object that isn't a PLAYER it still adds it on, EVEN when I have an if v:IsA function.
How to fix this?
local Pc = game.Workspace.Values.PlayerCount
function Add()
for i, v in pairs(game.Players:GetChildren())do
if v:IsA("Player")then
Pc.Value = Pc.Value + 1
end
end
end
function Subtract()
for i, v in pairs(game.Players:GetChildren())do
if v:IsA("Player")then
Pc.Value = Pc.Value - 1
end
end
end
game.Players.ChildAdded:connect(Add)
game.Players.ChildRemoved:connect(Subtract)
