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

How do I create an unbreakable loop?

Asked by 5 years ago

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?

1
It is as simple as not using break. You're making it too hard on yourself. DeceptiveCaster 3761 — 5y
0
^ agreed. easier ways, unsimplified. NickAtNick 163 — 5y
0
I don't think you understood what I meant User#27158 -5 — 5y
0
do you mean when the player respawns the script has to re-run? Fad99 286 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

(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.

0
Don't use while wait() do. User#24403 69 — 5y
0
did I not delete this? I read the question and details wrongly. and why not? I use that all the time. NickAtNick 163 — 5y
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. User#24403 69 — 5y
0
I believe that nowadays the superior waiting loop is repeat wait() until <condition>. As incapaxx said, while wait() do is not a good loop to use yet it works. DeceptiveCaster 3761 — 5y
0
oh okay. NickAtNick 163 — 5y
Ad
Log in to vote
0
Answered by 5 years ago
Edited by User#24403 5 years ago
while true do
    -- code here
end

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

Answer this question