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

How do I stop loops using another script?

Asked by 9 years ago

What I did was make a Boolean value so a script could interact with another. But how can I use that to my advantage in stopping a while true do script in the middle of the piece of code at any point in time?

0
Just do, "if (value) == false then break end", replace value to the boolean. M39a9am3R 3210 — 9y

2 answers

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

You're explicitly stating that something should only done while this is true, so that means you shouldn't be using a whiletrue loop, you should be using an actual condition:

while someCondition do
    -- (your loop)
end

Alternatively, as M39a9am3R suggested, you could use a break to emulate this:

while true do
    if not someCondition then
        break -- Stop the loop ("break" the loop)
    end
    -- (your loop)
end
Ad
Log in to vote
0
Answered by 9 years ago

you can stop it by using another script and putting a Bool Value in the script thats going to stop it. Have the script change it by doing script.stop.Value = true or what ever you want it to be.

Then in the one you want to stop, just add this to the top

if not game.Workspace.stopScript.stop.Value then
while true do
    --stuff
end
end

Answer this question