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

Is it possible to check the amount of players on a team?

for _,v in pairs(game.Players:GetPlayers()) do
	if v.TeamColor == BrickColor.new("Bright blue") then
		blueteam.Value = blueteam.Value + 1
	elseif v.TeamColor == BrickColor.new("Bright red") then
		redteam.Value = redteam.Value + 1
	end
end

I am trying to make it so it checks the amount of players on a team, so it would say print 5, being 5 people are on red team.

3 comments

0

This is correct, assuming redteam and blueteam are defined. Make sure you remember to reset the values between tests, though.

0

yeah it works, but when there is 2 players, it says 1 for blue value and 2 for red, even though theres only 1 for each team?

0

how can I get it to just count the players so if theres 8 people it says 4 blue 4 red

1 answer

✓ Accepted answer

You can check all the players and find their team color, essentially letting you see how many players are on a team.

teamtable1 = {}
for i,v in pairs(game.Players:GetChildren()) do
	if v.TeamColor == BrickColor.new("Color Here") then -- Checks every player for their Team Color
		table.insert(teamtable1,v)
	end
end

2 comments

0

ok so I just add print(teamtable1)???

0

i eddited my answer with what i have. It works, with one player, giving blue + 1 vlue, but when I try with 2 players it says blue = 1 and red = 2, why is this?

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