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 8 years ago

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

while true do
    wait(3)
    contestants = {}
    while #contestants < 3 do
    status.Value = "Waiting For Players"
    for _, player in pairs(game.Players:GetPlayers()) do
        if player and player.Character then
            local humanoid = player.Character:WaitForChild("Humanoid")
            if humanoid and humanoid.Health > 0 then
                table.insert(contestants, player)
            end
        end
            if #contestants >= 3 then
                break
            else
        end
    end
    end
end

1 answer

Log in to vote
2
Answered by
Cuirs 10
8 years ago
local Players = {} -- Create the Players table outside the while loop.

while wait() do
    while #Players < 3 do
        wait()
        print("Hi")
        for _,Player in pairs(Game.Players:children()) do -- Try using :children() or :GetChildren() instead of :GetPlayers().
            table.insert(Players, Player)
        end
        if #Players >= 3 then
            break
        end
    end
end

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