Understanding Coroutines with the use of functions inside the coroutine?

I’m having trouble understanding how coroutines work after messing around with them and going through forms.
When I created a coroutine function I noticed my timer I had worked outside of the coroutine function that is shown below.

coroutine.resume(coroutine.create(function()
	while GAME_ACTIVE == true do
		for num, child in pairs(index:GetChildren()) do				
			TileChange(child)							
		end
	end
end))

However, this has no effect on my function TileChange(child) within the function.
The function TileChange has a wait parameter as well as change color. How can I get the TileChange function running at the same time for each child with Coroutines?

You need to create a new coroutine for each children. Additionally using coroutine.wrap in this manner is shorter and still does the job.

	while GAME_ACTIVE == true do
		for num, child in pairs(index:GetChildren()) do	
coroutine.wrap(function()			
			TileChange(child)
end)()					
		end
	end

2 Likes

I see, that makes sense!
I did this and it appears it’s not using wait(randomnumber) and it’s just trying to change the tile color as fast as possible