What do you want to achieve?
So I want to break the FOR loop when the IF statement is true.
What is the issue?
Even if the statement is true FOR loop is still going.
InRound = bool value.
PlayersAmountInMiniGame = int value.
Status = string value.
function roundTimer()
while true do
for i = intermissionLength, 1, -1 do
InRound.Value = false
Status.Value = "Intermission: "..i.." seconds left!"
wait(1)
end
Status.Value = "Ready?"
wait(1)
for i = quickCounter, 1, -1 do
InRound.Value = false
Status.Value = i
wait(1)
end
InRound.Value = true
Status.Value = "GO!"
wait(2)
for i = roundLength, 1, -1 do
InRound.Value = true
Status.Value = "Game: "..i.." seconds left!"
wait(1)
if InRound.Value == true and playersAmountInMiniGame == 0 then
break -- loop is still going, but it shouldn't
end
Status.Value = "Everyone DIED!"
end
Status.Value = "END!"
wait(2)
end
Status.Value = "Everyone DIED!"
InRound.Value = false
end
Are you sure you are counting the Players? Assuming its a table, it would be #playersAmountInMiniGame
It could also be the that the Previous loop hasn’t ended, or that the condition isn’t met, its very Likely playersAmountInMiniGame is returning false
AlivePlayers = {}
for number, player in game.Players:GetPlayers() do -- Gets Players
table.insert(AlivePlayers, player) -- Inserts Players
player.Character.Humanoid.Died:Connect(function() -- Connects a event when they die
table.insert(AlivePlayers, AlivePlayers[player]) -- Removes Player
end)
end
From there you can count how many:
If #AlivePlayers < 1 and InRound.Value == true then
-- code
end
AlivePlayers = {}
function roundTimer()
while true do
for i = intermissionLength, 1, -1 do
InRound.Value = false
Status.Value = "Intermission: "..i.." seconds left!"
wait(1)
end
for number, player in game.Players:GetPlayers() do -- Gets Players
table.insert(AlivePlayers, player) -- Inserts Players
player.Character.Humanoid.Died:Connect(function() -- Connects a event when they die
table.insert(AlivePlayers, AlivePlayers[player]) -- Removes Player
end)
end
Status.Value = "Ready?"
wait(1)
for i = quickCounter, 1, -1 do
InRound.Value = false
Status.Value = i
wait(1)
end
InRound.Value = true
Status.Value = "GO!"
wait(2)
for i = roundLength, 1, -1 do
InRound.Value = true
Status.Value = "Game: "..i.." seconds left!"
wait(1)
if InRound.Value == true and #AlivePlayers < 1 then
break -- loop is still going, but it shouldn't
end
Status.Value = "Everyone DIED!"
end
Status.Value = "END!"
wait(2)
end
Status.Value = "Everyone DIED!"
InRound.Value = false
end
Just Pasted them into the place i feel like who be best
Try playersAmountInMiniGame.Value == 0? Also consider changing the name to playersLeft. And maybe <= 1 would be better because if there’s one player left, they win.
Sorry if somebody said this already, I didn’t read the replies yet.
If there is no code after the while loop, use return, otherwise make a variable above the for loop, and set it to true if you want to break the while loop. Use an if statement after the for loop checking this variable if it should break the while loop.
while true do
local whilebreak = false
for i = 1, 10 do
if i * 2 == 4 then whilebreak = true break end
end
if whilebreak then break end
end
function roundTimer()
while true do
local whileBreak = false
for i = intermissionLength, 1, -1 do
InRound.Value = false
Status.Value = "Intermission: "..i.." seconds left!"
wait(1)
end
Status.Value = "Ready?"
wait(1)
for i = quickCounter, 1, -1 do
InRound.Value = false
Status.Value = i
wait(1)
end
InRound.Value = true
Status.Value = "GO!"
wait(2)
for i = roundLength, 1, -1 do
InRound.Value = true
Status.Value = "Game: "..i.." seconds left!"
wait(1)
if InRound.Value == true and playersLeft.Value == 0 then
whileBreak = true
break
end
if whileBreak then
break
end
Status.Value = "Everyone DIED!"
end
Status.Value = "END!"
wait(2)
end
Status.Value = "Everyone DIED!"
InRound.Value = false
end
for i = roundLength, 1, -1 do
InRound.Value = true
Status.Value = "Game: "..i.." seconds left!"
wait(1)
if InRound.Value == true and playersAmountInMiniGame == 0 then
i:Destroy()
end
You:
for i = roundLength, 1, -1 do
InRound.Value = true
Status.Value = "Game: "..i.." seconds left!"
wait(1)
if InRound.Value == true and playersAmountInMiniGame == 0 then
break -- loop is still going, but it shouldn't
end