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.

3 comments
try print debugging
also you are using Player.Team.Name, maybe you mean Player.Team = "teamname"????
also you are wrapping a for loop of all the players in the game in another for loop of all the players in the game which may be a problem