Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why isnt this team balancing script working, its the last bug in my entire game?[SOLVED]

Asked by 6 years ago
Edited 6 years ago

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.

0
try print debugging abnotaddable 920 — 6y
0
also you are using Player.Team.Name, maybe you mean Player.Team = "teamname"???? abnotaddable 920 — 6y
0
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 abnotaddable 920 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago

Use the team name and color.

local team = ["

greenteam = game.Teams.["Green Team"]
player.greenteam.Color = "Green"


"]

Etc.

0
Update: remove the " at the end of [ and beggining of ] User#17915 0 — 6y
0
and add player.greenteam.Name at the end User#17915 0 — 6y
0
There's an edit button, dude Validark 1580 — 6y
Ad
Log in to vote
0
Answered by 6 years ago
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

Answer this question