I have a script that gets 4 teams from Lighting, clones them, puts them in the Teams service, and then (is supposed to) assigns players to it. The problem is, it won't assign players to the teams. This is the script for cloning the teams/map, and moving them to the right place:
map = game.Lighting.Crossroads:Clone() red = game.Lighting.Red:Clone() blue = game.Lighting.Blue:Clone() green = game.Lighting.Green:Clone() yellow = game.Lighting.Yellow:Clone() map.Parent = game.Workspace red.Parent = game.Teams blue.Parent = game.Teams green.Parent = game.Teams yellow.Parent = game.Teams
That all works fine and dandy, but when I try to assign players to the teams, with:
player = game.Players:GetChildren() for p = #player, #player do if(player[p].TeamColor==BrickColor.new("White"))and (player[p].Character~=nil)then player[p].TeamColor = blue.TeamColor end end for p = #player/2, #player do if(player[p].TeamColor==blue.TeamColor)and (player[p].Character~=nil)then player[p].TeamColor = red.TeamColor end end for p = #player/2, #player do if(player[p].TeamColor==red.TeamColor)and (player[p].Character~=nil)then player[p].TeamColor = green.TeamColor end end for p = #player/2, #player do if(player[p].TeamColor==blue.TeamColor)and (player[p].Character~=nil)then player[p].TeamColor = yellow.TeamColor end end
It doesn't work. I looked in output, and nothing shows up. Please help :)
local players = {} for a,b in pairs(game.Players:GetChildren()) do table.insert(players,b) end for i = 1,#players do if i % 1 == 0 then players[i].TeamColor = BrickColor.new("Bright red") -- change to the color you want team 1 elseif i % 2 == 0 then players[i].TeamColor = BrickColor.new("Bright blue") -- again change to the color you want elseif i % 3 == 0 then players[i].TeamColor = BrickColor.new("Bright yellow") -- again elseif i % 4 == 0 then players[i].TeamColor = BrickColor.new("Bright green") -- again end end
Should work. I scripted it in here so I never tested it (my studio's down atm and it's working).
Here is the works: (Extremely inefficient, but HEY, IT WORKS! :D)
local Teams ={green, yellow, red, blue} function AssignRandomTeam(Player, CurrentTeam) for x=1,#Teams do if Teams[x] ~= CurrentTeam then Player.Parent = Teams[x] end end function Relocate(Team) for i, v in pairs(Team:GetChildren()) do AssignRandomTeam(v, Team) return end end while wait() do local NumBlue = blue:children() local NumRed = red:children() local NumYell =yellow:children() local NumGrn =green:children() local TmNums = {NumGrn, NumYell, NumBlue, NumRed} for i = 1, #TmNums do if #TmNums[i] > #TmNums/game.Players.NumOfPlayers then Relocate(Teams[i]) end end end