Need help with while true loops

I’m trying to make while loops that have to be separate to activate the fireworks for my new year’s event. But I can’t seem to figure out how to write 2 or more while loops under each other. Is there a possible way to do it or must I do it another way?

Create different threads for each loop, this can be achieved using coroutines:

coroutine.wrap(function()
	while task.wait(1) do 
		print("loop 1")
	end
end)()
coroutine.wrap(function()
	while task.wait(1) do 
		print("loop 2")
	end
end)()

or with the new task library:

task.spawn(function()
	while task.wait(1) do 
		print("loop 1")
	end
end)
task.spawn(function()
	while task.wait(1) do 
		print("loop 2")
	end
end)

PS: when the script gets destroyed/disabled, the loops will still run.

2 Likes

Thank you so much, this is going to be so useful. :slightly_smiling_face: :

1 Like