Hello, thank you for reading. What I'm trying to do is make a team where there is a limit. What I'm trying to do is make a IntValue which adds +1 to itself each time a player is identified as a player who is on the prison guard team. It is not working and I don't know why.
The other problem is that once a player leaves the server, I want the script to recheck if the person who left was on the prisoner team. If he was, then the IntValue will be subtracted by 1.
If anyone can help me with these two problems, I'll be so grateful towards you.
GuardCount = game.Workspace.GuardCount players = game.Players:getChildren() function addGuards() for i = 1, #players do if players[i].Character ~= nil then if players[i].TeamColor == game.Teams.PrisonGuard.TeamColor then GuardCount.Value = GuardCount.Value + 1 end end end end game.Players.ChildAdded:connect(addGuards)
On line 2, you're getting all of the players. You do this once, right as the script is created, so you get zero players. This is never updated. On line 5, you're iterating through the list of players that were in the game when the script was created (the zero players.)
You want to move line 2 to before line 5.
local GuardCount=workspace.GuardCount game.Players.PlayerAdded:connect(function() local players=game.Players:GetPlayers() for i=1,#players do if players[i].TeamColor=game.Teams.PrisonGuard.TeamColor then GuardCount.Value=GuardCount.Value+1 end end end)