How to stop a while true loop after the loop plays?

while isOpening do
wait()
--do something
end
isOpening = false --im trying to set the True to false after the loop plays but u cant cause it will infinitely wait

how could i set isOpening to false after the while loop?

That should stop it, if not this will.

if isOpening then
    break
end

If this doesn’t work, then just use break to end the loop whenever.

well yes ik i can use break to stop it, if i do this how would i get the loop to play multiple times then stop it?

You could do this:

task.spawn(function()
    while IsOpening do
        --stuff
    end
end)

Now, that will start in a separate thread, so when you change IsOpening to false it will stop the loop.

1 Like

works exactly how i wanted, thank you

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.