Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

0

try print debugging

0

also you are using Player.Team.Name, maybe you mean Player.Team = "teamname"????

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

2 answers

Use the team name and color.

local team = ["

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


"]

Etc.

3 comments

0

Update: remove the " at the end of [ and beggining of ]

0

and add player.greenteam.Name at the end

0

There's an edit button, dude

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

This discussion is preserved as it was. New answers, comments, and votes are closed.