Why can't I break this active table?

I have had trouble with my table, what I want to do is if there is one person left in the round, or Luigi has died, then I want everything to reset and put all of the players in the lobby. I have set up things to insert into an active table until the round is over. The problem is this table will not break. I have tried looking on the web for answers, but I couldn’t find anything for what I was looking for. Here is part of my script where the issue occurs, any more part of this script I can give, but I feel it won’t be necessary.

Script
	local localtimer = roundtime
	while localtimer > 0 do
		wait(1)
		localtimer = localtimer - 1
		print(localtimer)
		local activepeople = {}
		print(#activepeople)
		for _, B in pairs(teams["Boo's"]:GetPlayers()) do
			if B then
				table.insert(activepeople, B)
			end
			for _, KB in pairs(teams["King Boo"]:GetPlayers()) do
				if KB then
					table.insert(activepeople, KB)
				end
			end
			for _, l in pairs(teams.Luigi:GetPlayers()) do
				if l then
					table.insert(activepeople, l)
				end
			if #activepeople <= 1 or not l then
				break
			end
			end
		end
	end
	roundtime = 0

From what I think you trying to do is access the active people later in the script right? If you are then you should have the

local activepeople = { }

outside of the while loop since every time the while loop is called that activepeople variable is deleted and remade.

Also did you mean to have for every Boo there is everyone on the luigi and king boos added to the activepeople?

3 Likes

oops, sorry for the mistake I noticed in my topic and the long wait, I realized I put the print in the wrong spot. I had that table in the while loop to reset on purpose, so that way the script doesn’t add multiple people to the table leading it to not break. I ended up fixing the script by correcting the mistakes and changing the spots of where the loops/statements should be.

Here is the improved script for anybody who needs it
	local localtimer = roundtime
	while localtimer > 0 do
		wait(1)
		localtimer = localtimer - 1
		print(localtimer)
		local lactive = false
		local activepeople = {}
		for _, B in pairs(teams["Boo's"]:GetPlayers()) do
			if B then
				table.insert(activepeople, B)
			end
			for _, KB in pairs(teams["King Boo"]:GetPlayers()) do
				if KB then
					table.insert(activepeople, KB)
				end
			end
			for _, l in pairs(teams.Luigi:GetPlayers()) do
				if l then
					lactive = true
					table.insert(activepeople, l)
				end
			end
		end
		if #activepeople <= 1 or not lactive then
			break
		end
	end
	roundtime = 0

@froghopperjacob thanks for the help though I really appreciate it and your explanation is really good to know for people who might be new! :grin: