Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How do I count the number of people on a certain team?

Asked by 10 years ago

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.

3 answers

Log in to vote
1
Answered by 10 years ago
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")))
Ad
Log in to vote
0
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
10 years ago
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.

0
How would I be able to add the numbers into a number value? billybobtijoseph 1 — 10y
0
Instance.new("NumberValue").Value=Number 1waffle1 2908 — 10y
Log in to vote
-2
Answered by 10 years ago

Okay. players = game.Teams.GreenTeam:GetChildren() print(#players) [#players = amount of players on green team]

0
I can't post lines, it just merges them together. Sorry about that. plebgod 0 — 10y

Answer this question