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

How can I detect if ENTIRE server is in one team?

It gets pass the if statement if only one person joins the black team. How can I structure it to get pass the if statement when everybody is in the black team?

for _,v in pairs(game.Players:GetPlayers()) do
		if v.TeamColor ~= BrickColor.new("Crimson") and v.TeamColor == BrickColor.new("Really black")  then
			script.Parent.AllDead.Value = true
		end
end

1 answer

✓ Accepted answer

You cannot reasonably do this inside the for loop.

You should consider each player, record if they are all on that team, then check after the loop.


Imagine you had players A, B, C. You want to know if they're all on team team.

That might look like:

allOnTeam = true
	and a.TeamColor == team
	and b.TeamColor == team
	and c.TeamColor == team

(I include the true to show how to write this without making the first one special)

It's easy to make this into a for loop:

local allOnTeam = true
for _, player in pairs(game.Players:GetPlayers()) do
	allOnTeam = allOnTeam and player.TeamColor == team
end

if allOnTeam then
	-- all on one team
else
	-- at least one not on team
end

Another way to approach this is to make a function that tells you who is on a team (and maybe who is not), and to look at the sizes of that.

Since you're probably interested in who is on what team at some point, that's a useful function to have.

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