Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Why isn't my loop breaking?!

Asked by 9 years ago

For some reason this loop doesn't seem to be breaking. Help!

01while true do
02    wait(3)
03    contestants = {}
04    while #contestants < 3 do
05    status.Value = "Waiting For Players"
06    for _, player in pairs(game.Players:GetPlayers()) do
07        if player and player.Character then
08            local humanoid = player.Character:WaitForChild("Humanoid")
09            if humanoid and humanoid.Health > 0 then
10                table.insert(contestants, player)
11            end
12        end
13            if #contestants >= 3 then
14                break
15            else
16        end
17    end
18    end
19end

1 answer

Log in to vote
2
Answered by
Cuirs 10
9 years ago
01local Players = {} -- Create the Players table outside the while loop.
02 
03while wait() do
04    while #Players < 3 do
05        wait()
06        print("Hi")
07        for _,Player in pairs(Game.Players:children()) do -- Try using :children() or :GetChildren() instead of :GetPlayers().
08            table.insert(Players, Player)
09        end
10        if #Players >= 3 then
11            break
12        end
13    end
14end

I rewrote the whole script, this script works.

I noticed with your script you used :GetPlayers().. Try using :GetChildren()/:children() in your script. Also, don't put the contestants = {} in the while loop because it'll reset the contestants value every 3 seconds.

I hope this is of some help.

Ad

Answer this question