Attempt to index boolean with 'Team'

Hello, i’m making a balancing team system but I have a problem.
When I change the team, a error is return in the output attempt to index boolean with 'Team'
Who can help me?

The script:

local function BalanceTeams(plr)
	local teams = game.Teams:GetChildren()
	local getLobbyTeam = table.find(teams, game.Teams.Lobby)
	
	if getLobbyTeam then
		table.remove(teams, getLobbyTeam)
	end
	
	local sel = math.random(1,4)
	local count = 0
	
	local SelectedTeam
	
	for i, t in ipairs(teams) do
		count += 1
		
		if sel == count then
			SelectedTeam = game.Teams[t.Name]
		end
	end
	
	local _t = teams
	
	local GetActualTeam = table.find(_t, SelectedTeam)
	if GetActualTeam then
		table.remove(_t, GetActualTeam)
	end
	
	local retry = false
	
	for i, t in ipairs(_t) do
		if #SelectedTeam:GetPlayers() > #t:GetPlayers() then
			retry = true
		end
	end
	
	if retry == true then
		return RetryBalance(plr)
	else
		plr.Team = game.Teams[SelectedTeam.Name]
	end
end

function RetryBalance(plr)
	BalanceTeams(plr)
end

First thing that i can think of is that plr is a boolean value and not sctually a player. Does it say in which line it errors?

1 Like

oh yes, when I called the function, I didn’t check but I called with a boolean value…

1 Like
if retry == true then
if retry == false then

Statements like these are also unnecessary, you can simply do the following instead:

if retry then
if not retry then