In my murder game I have a while true do to handle all of the rounds, thing is inside of those while true do im doing
for i = 10,1,-1 do
end
I want this loop to stop if everyone dies, I already made that but how do I make the for i loop stop? Btw idk if break works in for i loops but what if it breaks the while true do loop
for i = 10, 1, -1 do
-- random code
-- random code
-- random code
-- random code
-- random code
if i == 1 then
break -- this will not stop the loop below but instead, stop the loop it is inside, which is the loop above
end
for a = 230, 30, -1 do
end
end
But if you mean the closest in the sense that it checking the closest above, then yeah, you’re correct.
You need to have some sort of indication about players’ life status. You can’t just listen to the “Died” event, as players will respawn in the lobby. So, have a bool value called “Playing” inside every player. Set it to true when a game starts, and false when the player dies.
To make the loop break, check the Playing value of every player after every cycle. Like:
for i = 1, 10 do
-- Your code
local EveryoneDead = true
for _, Player in pairs(Players:GetPlayers()) do
if Player.Playing.Value then
EveryoneDead = false
break
end
end
if EveryoneDead then
break
end
end
for i = 1, 10 do
-- Your code
local PlayersAlive = 0
for _, Player in pairs(Players:GetPlayers()) do
if Player.Playing then
PlayersAlive = PlayersAlive + 1
end
end
if EveryoneDead == 0 then
break
end
end