For loop breaking with 1 player but not with 2 players

Hello, so I just finished my round system but when I try breaking a for loop when there is only 1 player left on a table it works when there is only 1 player on the server but with 2 players it doesn’t work how can fix this?
Here is my code:

local module = require(script:WaitForChild('Functions'))

local status = game.ReplicatedStorage:WaitForChild('Status')

local playersIngame = {}

function removePlayer(p)
	for i, v in pairs(game.Players:GetPlayers()) do
		if v.Name == p.Name then
			table.remove(playersIngame, v)
		end
	end
end


game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		Character.Humanoid.Died:Connect(function()
			if table.find(playersIngame, Player) then
				removePlayer(Player.Name)
				print(Player.Name.. " has been removed")
			end
		end)
	end)
end)

function startround()

	module.ChooseImposter()
	
	wait()
	
	module.TPplayers()
	
	for i, v in pairs(game.Players:GetPlayers()) do
		table.insert(playersIngame, v)
		print(v.Name..' Was added')
	end
end


function endRound(player)
	for i, v in pairs(game.Players:GetPlayers()) do
		if v:FindFirstChild('ImposterValue') then
			v.ImposterValue:Destroy()
		end
	end
	module.TPplayersBack()
end

local time1 = 10
	
local time2 = 20

while wait() do
		
	status.Value = '4 players needed to start a game'
	
	repeat wait(.2) until game.Players.NumPlayers >= 1
	for i = time1, 0, -1 do
		status.Value = 'Starting in '..i..' seconds'
		wait(1)
	end
	
	startround()
	
	for i = time2, 0, -1 do
		status.Value = i..' seconds left'
		print(#playersIngame)
		if #playersIngame == 1 then
			break
		end
		wait(1)
	end
	
	endRound()
end

Thank you!

2 Likes

It’s because you’re checking if it’s exactly 1 instead of doing something like.

if #playersIngame <= 2 then — is the amount of players less than or equal to 2?
    break — if so break!
end

— rest of code

Will it work with more than 2 players?

You already made a similar topic about this:

You also didnt mark a solution.

In that first post I told you how to do it and you could have just change it.

1 Like