I am trying to make a team balance script and I have come up with this, It teleports players to the game and also fires a client which turns off a GUI which isnt important, But then its supposed to balance the teams but it doesnt. It just basically goes right over the code and nothing happens. Does anyone have any ideas?
Heres the code
local skip = false local spawns = chosemap:WaitForChild("Spawns"):GetChildren() for _, player in pairs(game.Players:GetChildren()) do enableLockedCamera:FireClient(player) if player and #spawns > 0 then local uppertorso = player.Character:WaitForChild("HumanoidRootPart") local allspawns = math.random(1, #spawns) local randomspawn = spawns[allspawns] if randomspawn and uppertorso then table.remove(spawns, allspawns) uppertorso.CFrame = CFrame.new(randomspawn.Position + Vector3.new(0, 3, 0)) for _, each in pairs(game.Players:GetPlayers()) do if skip == false then skip = true player.Team.Name = "Green Team" else skip = false player.Team.Name = "Red Team" end end if #game.Teams["Green Team"]:GetChildren() >= #game.Teams["Red Team"]:GetChildren() then player.Team.Name = "Green Team" else player.Team.Name = "Red Team" end end end end
Thank you guys for your time. This is literally the very last problem in my game that I have to fix, And I am really looking forward to getting it done.
Use the team name and color.
local team = [" greenteam = game.Teams.["Green Team"] player.greenteam.Color = "Green" "]
Etc.
TeamG = game.Teams["Green Team"] TeamR = game.Teams["Red Team"] if #TeamG:GetChildren() > #TeamR:GetChildren() then player.Team.Name = "Red Team" elseif #TeamG:GetChildren() < #TeamR:GetChildren() then player.Team.Name = "Green Team" else player.Team.Name = "Green Team" end