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

How do I break a waiting script? Stopping wait(1) after being ran before completing task?

Asked by
Drodex 2
5 years ago
Edited 5 years ago

For 4 consecutive days, I've been looking for a solution to stop a script from performing its waiting task after the wait(1) has been ran. I want to stop the script from waiting in the middle whilst waiting.

The only conclusion I've come up with is to do script:Destroy() and then re-clone it but I rather avoid doing that.

Is there any way I can make this work?

while wait(5) do
    print("Script is waiting 5 seconds but I want it to break the while loop while it's waiting.")
end
--Outside function or method to break this while loop before wait() re-runs task? ^

2 answers

Log in to vote
0
Answered by 5 years ago

You could use break for stopping the loop, or if you want it to stop after a specific time, use for loops, just like this example:

for i = min, max do
-- function
end

Hope I helped.

0
break happens after the wait task is performed. For loops run instantly and adding a wait(0.1) inside them and setting max to 10 is an inaccurate wait(1). Sorry, didn't answer my question. Drodex 2 — 5y
0
I see what you want now, didnt read good. Sorry, I don't know anything that can work like that. EternalScythe 222 — 5y
0
Actually surprisingly recreating a wait(1) using for loops actually worked. Drodex 2 — 5y
0
then accept my answer if u can ;) EternalScythe 222 — 5y
View all comments (2 more)
0
I'm not sure how to do that. LOL help, sorry. Drodex 2 — 5y
0
I can't really accept your answer because well.. Even the solution that I created doesn't 'really' break a wait(). I got the idea to my solution thanks to you but however It doesn't really answer the question. Drodex 2 — 5y
Ad
Log in to vote
0
Answered by
Drodex 2
5 years ago
Edited 5 years ago

Found out the solution on my own.

ifStepped = true

function clock()
    spawn(function()

        for i = 1, 10 do
            i = i + 1
            wait(0.1)

            if i == 10 then 
                --[[If one second complete then we can re-run clock.
                    can also use this and modify this if statement to see if the player stepped out of the region to stop the timer. This way when the player re-joins Region3 the timer / player points re-start exactly from 0.
                --]]
                print("broke")
                ifStepped = true
                break
            end
        end
    end)
end

spawn(function()
    while wait(0.1) do
        --This while loop checks if player is in a region3 (just an example)
        print("Ran")
        --Running the 1 second to see if player stepped out of region 
        if ifStepped == true then
            ifStepped = false
            --If this is true we run clock and we changed it to false not to run clock again.
            clock()
        end
    end
end)

Answer this question