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

How do I break a sequence?

Asked by 10 years ago

EDITED

Ok so lets say I have a sequence, like so:

local SequenceIsStopped = false
function Sequence()
    --Do stuff
    wait(1)
    --Do stuff
    wait(1)
end

And I wanted to stop the sequence mid-way, how would I go by doing so? The only other way that I know of is putting a conditional that breaks the sequence if SequenceIsStopped = true at the end of every single line. Is there a more effective way? Or is that the only way?

Note: This is what I was talking about when I said that the way I know of is using a conditional:

local SequenceIsStopped = false
function Sequence()
    if SequenceIsStopped then break end
    --Do stuff
    if SequenceIsStopped then break end
    wait(1)
    if SequenceIsStopped then break end
    --Do stuff
    wait(1)
end

I know it's terribly inefficient

2 answers

Log in to vote
2
Answered by 10 years ago
for i = 1, 5 do
    print(i)
    wait(1)
    if Stop then
        break
    end
end

--The loop should stop if the variable Stop becomes true anywhere in the script.
0
That's a good idea, but not exactly what I was looking for. Read the edited version of the question TurboFusion 1821 — 10y
0
What were you looking for? The question looks the same. Thewsomeguy 448 — 10y
0
I'm not trying to get it to print something, like if i wanted it to tween a gui 5 times, but i wanted it to stop mid-way TurboFusion 1821 — 10y
Ad
Log in to vote
0
Answered by 10 years ago

How about this:

function CheckStopWork()
    if Stop then
        return break
    end
end

for i = 1, 5 do
    print(i)
    wait(1)
    CheckStopWork()
end

-- It should break the loop if "Stop" becomes true from somewhere else in the script.

I have no means of testing this, so I hope it works.

0
It errors because you can't return break Thewsomeguy 448 — 10y

Answer this question