I am trying to count the number of people on a green team and a blue team and place them in 2 different values named "a" and "b." Can someone help me out? I don't exactly have a code yet because I don't know how I would be able to set this up.
COMMUNITY QUESTION
How do I count the number of people on a certain team?
3 answers
function CountPlayers(teamcolor)
local count=0;
for i,v in next,Game.Players:GetPlayers() do
if v.TeamColor==teamcolor then
count=count+1
end
end
return count;
end
--EXAMPLE:
print(CountPlayers(BrickColor.new("Bright red")))
local a={}
local b={}
for _,v in pairs(game.Players:GetPlayers())do
if v.TeamColor==BrickColor.new("Bright green")then
a[#a+1]=v
else
b[#b+1]=v
end
end
Checks each player's team color and adds their player to table a if their TeamColor is Bright green or b otherwise.
Okay. players = game.Teams.GreenTeam:GetChildren() print(#players) [#players = amount of players on green team]
1 comment
0
I can't post lines, it just merges them together. Sorry about that.
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
How would I be able to add the numbers into a number value?
Instance.new("NumberValue").Value=Number