Problem with checking if a team has 0 players

I want to make a script where once the amount of players in a team gets to 0, it deletes the team.

The main issue is the fact that is simply doesn’t work. I tried making it print “working” if it works, but it’s clearly something to do with the script itself.

I’ve tried looking for scripts such as how to check if a team has 0 members, however this just ends up not loading the team at all.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

	elseif player:IsInGroup(AAB) then
		local AAB ="Team")
		AAB.Parent = game.Teams
		AAB.AutoAssignable = false
		AAB.TeamColor ="Maroon")
		AAB.Name = "16th Air Assault Brigade"
		player.Team = game.Teams:FindFirstChild("16th Air Assault Brigade")		
		while true do
			if AAB:GetPlayers() == nil then
				print("Team has been deleted")
1 Like

add a wait value inside while true do , so it will work
edit like : wait(.1)

You don’t yield within your loop so it would cause a crash or prevent any other code within that script from running unless in a coroutine.

Try adding a wait() before your last end or even better, use an event to appropriately detect when the team has been deleted

local function onRemoved()
    if #AAB == 0 then
        print("destroying team") 
        -- listener:Destroy() is automatically called

you should change this variable to something else like AAC because it is confusing when you have argument in line over that.