A question about coroutines

I was just wondering what the limit to coroutines are. Lets say i wanted to make a Scrolling Frame with 500 children and i created a coroutine to tween each one. Would having that many coroutines cause lag? When does it become too many Coroutines?

Its not necessary for me to use the coroutines. Im just using them so i can have more precise timing when i make the children of the tweened GUI visible and tween the next GUI. I tried it and it didnt seem bad but, i decided i would also ask here just incase i was wrong.

That’s not at all what coroutines are intended for… Coroutines are just a more powerful version of spawn. Your weird distinction doesn’t even make sense, since coroutines run immediately while spawned functions will yield before running.

The issue is with having a ridiculous number of threads, not the method of creating them. You shouldn’t be doing this at all, spawn or no.

3 Likes

So having that many coroutines is bad? If so what do u suggest is best if you want to work with timing of tweens / order of code?

Why would you need 500 coroutines in the first place?

Tweens don’t yield I think, so you could probably just tween them all normally in the same thread.

Edit:

You could pass a callback function to execute after the tween is completed.

Like rogchamp said, you really shouldnt be doing that because it’s going to take alot of performance, the only reason you should be using coroutines is if your trying to run a piece of code along some kind of loop, or you want two pieces of code to run at once with very little delay.
Just make a function where you tween everything and call it once

The problem is what comes after the tween. I want to get stuff happening when the tween is completed for example making the viewport visible. But doing this without coroutines will interrupt the other tweens.

When i tried doing it, it didnt seem so bad. Perhaps it was because i have a good pc but, is there anything you can suggest as a substitute which would be better for performance?

Well your just tweening so just make a function where you tween everything and call it, tweens dont really effect performance unless your tweening like hundreds of actual parts in workspace at the same time

Oh alright, I could definitely optimise it but i was just asking just incase it was a normal thing. I knew that creating a lot of threads was bad but for some reason it worked fine for me when i tested it (Which is why i asked the question). Thanks for the reply :slight_smile:

1 Like

Ye like i said i could optimise it. I just wanted to check on here if using that many coroutines was fine :man_shrugging: . I just didnt want to go through extra work if it wasnt necessary.

1 Like