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

Team Balancing code not executing function?

This Scripts goal is to EVENLY divide plays between two teams at the start of the round, the issue is, the timer runs fine, but the players do not change teams.

--Round Variables
local timeint = 10 --Numbers read as seconds
local inttime = 10 --Numbers read as seconds
local requiredplayers = 2
--Round Objects
local status = game.ReplicatedStorage.Status
local teams = {"Red","Blue"}
--Assign Teams
function getPlayersOnTeam(teamColor)
    local players = {}
    for _, p in pairs(game.Players:GetPlayers()) do
        if p.TeamColor == BrickColor.new(teamColor) then
            table.insert(players, p)
        end
    end
    return players
end

function getSmallestTeam(teams)
    local numPlayers, smallestTeam = math.huge
    for team, players in pairs(teams) do
        if #players < numPlayers then
            numPlayers = #players
            smallestTeam = team
        end
    end
    return smallestTeam
end

	function Assign()
    local Red = getPlayersOnTeam("Bright red")
    local Blue = getPlayersOnTeam("Bright blue")
    local smallestTeam = getSmallestTeam({
        ["Bright red"] = Red,
        ["Bright blue"] = Blue
    })
end

--Main
while wait() do
	for i=inttime,1,-1 do
		wait(1)
		status.Value = "Intermission: "..i
	end
	Assign()
	for i=timeint,1,-1 do
		wait(1)
		status.Value = "Time Left: "..i
	end
end

Thanks

1 answer

Players don't change teams because you didn't put it in the script that they should be changing teams!

Maybe when you iterate through the list of players, change their teams how you want them to change?

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