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

How to I make a loop that will reset itself if something happens in the middle?

Asked by 4 years ago

I'd like to make a game loop script that'd restart on a condition, say like a player disconnects from the game in the middle of a battle, and the next lines are reliant on the player object existing, how do I just reset the script?

1 answer

Log in to vote
1
Answered by 4 years ago

The command break will break out of a loop. What you could do is have the entire loop in another loop, so when you break out of the game loop, the outside loop will make sure the game loop restarts. This is what I mean:

while wait() do
    --Everything in this loop will keep going when break is called on the enclosing loop
    while wait() do
        --Game loop stuff
        if not condition then
            break
        end
    end
end
0
Thanks! SwiftyDeveloper 4 — 4y
Ad

Answer this question