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 break a sequence?

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

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.

3 comments

0

That's a good idea, but not exactly what I was looking for. Read the edited version of the question

0

What were you looking for? The question looks the same.

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

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.

1 comment

0

It errors because you can't return break

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