Hey guys, as in the title. You know, you can do
while true do --Script here wait(10) end
but that will stop the whole script, or in other words, it would get stuck in there and repeat into an infinity AND BEYOND! But I need it to be looping infinitely "in the background" so the script can continue its way down but the infinite loop will be there. I hope you get it :D
I did some research, but didn't really help - I found something with WaitForAll, but I want to understand my scripts. Also, try to explain a bit (sentence above).
Thanks in advance!
you can use spawn()
or coroutines.
spawn(function() while true do print("john") wait(1) end end) local foo = coroutine.wrap(function() while true do print("hello john!") wait(1) end end) foo()
You can use the spawn function, which runs the function in a separate thread, like it's running in a different script.
spawn(function() while true do --script here wait(10) end end) print('hi')
You can also use coroutines https://developer.roblox.com/articles/Beginners-Guide-to-Coroutines https://developer.roblox.com/articles/Built-in-Functions-and-Variables/Roblox#spawn