How can i make a team auto balance system?

Hi! Recently i start a project and i work on team auto balance system i try make my own but it dosen’t work
it’s work for the first team “sun” but not for the “ocean” team then i try to delete the ocean to see if he can find the team but he succefuly delete the team then i don’t know where is my error

local TeamService = game:GetService("Teams")
local SunTeam = TeamService:WaitForChild("Sun")
local OceanTeam = TeamService:WaitForChild("Ocean")


local PlayerService = game:GetService("Players")

PlayerService.PlayerAdded:Connect(function(Player)
	if #SunTeam:GetChildren() < 2  then
		Player.TeamColor = BrickColor.new("Gold")
		Player.Team = SunTeam
	elseif #OceanTeam:GetChildren() < 2  then
		Player.TeamColor = BrickColor.new("Cyan")
		Player.Team = OceanTeam
	end
	wait(2)
end)

image
image
image

This is because you are checking how many children are under the team object itself, try making a counter for each team instead. Then, increase the counter each time a new player joins, also while checking if the counter is at its max. Also, use task.wait(), and there’s no need for yielding a function that only happens once when called.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.