Question about loops: Is it possible to loop something but still run something else in the same script?

Hey, i have a question about loops;

Ok so i want to loop something, I’m going to tween the colour of something and i want it to run indefinitely
the problem is, as far as i know, nothing will happen outside a script while a loop is running which is the point of it but i wanna know if there’s a way to still do stuff outside it while something is still looping sorry if it’s explained badly

basically


while true do
-- colour loop here
end

-- Stuff here will still work

again, I’m asking because i want to make a Chat Speaker have a rainbow colour font but i don’t want it to stop (or at least until the message isn’t visible) but i still want the functions in the script to work while that’s running

Yes!
There are Coroutines, and soon there will be parallel lua.

2 Likes

You can use coroutines:

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

while task.wait(1) do
	print("Y")
end
1 Like

Thank you, but i have 1 more question about it now

Would this make Coroutines Depreciated?

Coroutines and multithreading are actually separate things, so no, they will not be deprecated.

1 Like

No, coroutines likely won’t be depreciated anytime soon. Parallel lua was introduced so that you can run code pretty much at the same time. While coroutines weren’t made to run at the exact same time. They can be a bit slower depending on what you’re using them for.

1 Like

Okay, i see. Thanks for your help!