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!