Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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.

2 comments

0

How would I be able to add the numbers into a number value?

0

Instance.new("NumberValue").Value=Number

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.