Table is empty yet if statement doesnt run?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? everytime a player dies, this script will remove them from the table, and check if the table is empty, if the table is empty then it would end the game, but it only works for the DarkAlive, table and not the SurAlive table, please help!

  2. What is the issue? Include screenshots / videos if possible!
    The issue is the SurAlive table is empty yet if statement doesnt run? ( if #SurAlive == 0 then)

  3. What solutions have you tried so far? I’ve asked in many discords no responses, ive tried to reorganize the script to make sure all functions and such have ends but no luck

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!

game:GetService("Players").PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local SurAlive = {}
		local DarkAlive = {}
		repeat wait() until game.Workspace.GamePlay.Value == true
			for i, v in pairs(game.Players:GetPlayers()) do
				if v.Team == game.Teams.Survivor or v.Team == game.Teams.Juggernaunt then
					table.insert(SurAlive, v)
				end
			end
			for i, v in pairs(game.Players:GetPlayers()) do
				if v.Team == game.Teams.Darkness then
					table.insert(DarkAlive, v)
				end
		end
		print(#SurAlive)
		print(#DarkAlive)
		character:WaitForChild("Humanoid").Died:Connect(function()
			if player.Team == game:GetService("Teams").Juggernaunt or player.Team == game:GetService("Teams").Survivor then 
				table.remove(SurAlive, table.find(SurAlive, player))
				print(#SurAlive)
				print('removed')
				player.Team = game.Teams.Dead
				end
				if #SurAlive == 0 then 
					print('all dead')
					game.Workspace.SurvivorsDied.Value = true
					game.Workspace.GamePlay.Value = false
				end
			if	player.Team == game.Teams.Darkness then
				table.remove(DarkAlive, table.find(DarkAlive, player))
				print(#DarkAlive)
					player.Team = game.Teams.Dead
					end
				if #DarkAlive == 0 then 
					print('Dark dead')
					game.Workspace.BeastDied.Value = true
					game.Workspace.GamePlay.Value = false
				end
				print('removed')
		end)
	end)
end)