I saw problem in my script and i think the problem that is with stoping one loop which is in another loop, they two stops, so how to stop only this which i need to stop without stoping another one?
I use break for this.
can you give context?
just a snippet?
okey, so here is script for example.
while true do --Loop 1 i don't want to stop this loop
task.wait()
while true do -- Loop 2 i want to stop this loop only
task.wait()
break
end
end
Idk maybe break don’t stop first loop and problem is in something another, but i just want to know.
You can make variables and disable them whenever you want to disable that one loop. For example…
local loop1 = true
local loop2 = true
while loop1 do
task.wait()
while loop2 do
task.wait()
loop2 = false
end
end
Thank you,this is really helpful, but how do i stop for i = number,number loop or for i,v in pairs({}) loop?
To disable one of the for loops you can do the same thing if you’d like. Just put the second one in an if statement to check whether or not it is allowed to run or not.
local canloop = true
for i, v in pairs({}) do
if canloop then
for j, w in pairs({}) do
canloop = false
end
end
end
But this won’t stop the loop while it’s running? It will only not allow it to run the next time.
Thanks again, but what if i don’t want to second loop to continue run?
You can put the if statement inside the for loop instead, so that each time it runs, it will check if it can loop again.
I know, but loop still gonna run, and in my case it gonna create some lags, cuz i have like 100+ instances to check.