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

How do you count how many players are in a team?

I'm trying to make an FPS game that has team balance

1 answer

✓ Accepted answer

Well, to do this then you can make a table for each TeamColor, iterate through the players and insert them into a table corresponding to their TeamColor, and then check the number of indexes in each table.

(Sorry I couldn't explain this better..)

Example;

local red = {} --Red team
local blue = {} --blue team
local green = {} --green team

--Sort the players--
for i,v in pairs(game.Players:GetPlayers()) do
	--Check teamcolor, and sort accordingly--
	if v.TeamColor == game.Teams.Red.TeamColor then
		table.insert(red,v) --Sort player
	elseif v.TeamColor == game.Teams.Blue.TeamColor then
		table.insert(blue,v)
	elseif v.TeamColor == game.Teams.Green.TeamColor then
		table.insert(green.v)
	end
end

--Check amount of indexes--

local numRed = #red
local numBlue = #blue
local numGreen = #green

print("There are "..tostring(numRed).." players on the Red team")
print("There are "..tostring(numBlue).." players on the Blue team")
print("There are "..tostring(numGreen).." players on the Green team")

1 comment

0

Thanks! I looked at the script to get a better understanding

This discussion is preserved as it was. New answers, comments, and votes are closed.