Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I create an unbreakable loop?

So basically we all know the while true do and while wait() do loops. So those loops are technically unbreakable but can be breaked by using 'break' however, what I want is a loop that nevers breaks even if the character was reloaded. (im talking about a localscript for the player)

so it would be like:

(true) while wait() do print'Hello' break end

but what I want:

while wait() do
(characterloaded)
loop = true
end

the loop never breaks except when the 'break' is used. Is this possible?

4 comments

1

It is as simple as not using break. You're making it too hard on yourself.

0

^ agreed. easier ways, unsimplified.

0

I don't think you understood what I meant

0

do you mean when the player respawns the script has to re-run?

2 answers

(EDITED) Had to Edit because of some misread context in your details.

If you want to make an unbreakable loop, just do

while wait() do
-- ....
end

But if you would want your script to be broken use the if statement else then. By the way, your script will not continue to run if your while loop is never meant to be break. So be careful with scripting while loops.

5 comments

0

Don't use while wait() do.

0

did I not delete this? I read the question and details wrongly. and why not? I use that all the time.

0

while wait() do only works because of a hack; a trick. Use while true do. It's clearer. You probably don't even know how while wait() do works.

0

I believe that nowadays the superior waiting loop is repeat wait() until . As incapaxx said, while wait() do is not a good loop to use yet it works.

0

oh okay.

while true do
    -- code here
end

you can't break if it's inside a function, done.

This discussion is preserved as it was. New answers, comments, and votes are closed.