Team player counter doesn't work?

Hi everyone, I have been trying to make a round system recently and I cant figure it out how to make the round end when there is no more player in a specific team (in this case team Civilians). Everytime I try to print the number of players in the Civilians team during the round, it prints 0 despite I have set the players team to Civilians during the intermission of the round. I have check every forum and people have the similiar answer of using GetPlayers() but it still prints 0 regardless. Here is the code:

local team = game:GetService(“Teams”)
local civteam = #team.Civilians:GetPlayers()

function StartGame() – start game function

print(civteam)

end

function Intermission() – intermission function

re.OnServerEvent:Connect(function(plr, teamname)
if teamname == “Zombie” then
plr.Team = game.Teams.Zombies
elseif teamname == “Civ” then
plr.Team = game.Teams.Civilians
print(“Number of players in Civilians team:”, civteam)
elseif teamname == “Police” then
plr.Team = game.Teams.Polices
end
end)
end

1 Like

Maybe the documentation example on Teams will help out. They use events to keep track on the teams count so I would assume you can’t do the count the way you are trying.

PlayerAdded and PlayerRemove Events are there to fire every time someone joins a team, this is useful for stuff like player join a team notification,… My problem is even though I assign player team in the intermission, the team’s player count is always 0 for some reason.

Have you tried setting neutral as false?

plr.Neutral = false

if teamname == “Zombie” then
      plr.Team = game.Teams.Zombies
elseif teamname == “Civ” then
      plr.Team = game.Teams.Civilians
      print(“Number of players in Civilians team:”, civteam)
elseif teamname == “Police” then
      plr.Team = game.Teams.Polices
else
      plr.Neutral = true
end

The teams “AutoAssignable” are already off making them not neutral teams. So when I assign the player team nothing sure be neutral because the player has been assigned a team. Neutral means that the player hasn’t been assigned with any team. I also tested by changing Plr.Neutral boolen to false when Civilian team is selected and the result is still printing 0:

elseif teamname == “Civ” then
plr.Team = game.Teams.Civilians
plr.Neutral = false
task.wait(1)
print(“Number of players in Civilians team:”, civteam)

1 Like

You have to set the team to “AutoAssignable” or people can’t be assigned to that team without you making a script that puts them on Teams.

I did make a script to put people on the team they chose. For the record, turning on “AutoAssignable” spread the players evenly to all team involved and make the purpose of a “Choose your team intermission” useless.