How to assign players to random teams? Got it. First of all, use GetService for players instead just to be safe. So your line 02 should be for i, v in next, game:GetService('Players'):GetPlayers() do.
Create a variable for one of the team, so the loop knows when to add the player to that team or the other. local redTeam = true;.
For each loop check the new variable and switch it with redTeam = not redTeam.
Also to check for team color use v.TeamColor not v:FindFirstChild("TeamColor")
Whole code:
local redTeam = true;
function AssignTeam()
for i, v in next, game:GetService('Players'):GetPlayers() do
if v.TeamColor == BrickColor.new("Medium stone grey") then
if redTeam then
v.TeamColor = BrickColor.new('Bright red');
else
v.TeamColor = BrickColor.new('Bright blue');
end
redTeam = not redTeam;
end
end
end
I assumed you used the default red and blue Brickcolors
4 comments
You don't have to get a service through
game:GetService()from a serverside script. You should do it from a local script, however, as an exploiter could rename a service and break everything.Why does it put me to the team named "Neutral"?
@Link150 Thanks! But I trust in my boi FilterEnabled to prevent exploiters from breaking server stuff.
@FiredDusk It should put you in the Bright red and blue teams whatever the team names are. You can change both the teamcolors