Should I be cloning scripts to make new threads or use corountines?

While I have better performance in my scripts if I use corountines?

You could use object-oriented style development. Coroutines prevent the script from yielding by creating a new so-called thread. Of course, it’s not true 100% threading bc it’s not directly on the user’s CPU, but the same applied concept.

You can clone scripts, but during runtime, this could get extremely messy. I wrote a few articles on OOP if you are interested in taking a look at applying that concept.

2 Likes

Have you found the answer to your question? I also ask myself this question, but OOP, it’s not always good. I make 2 timers for my game and think about clone(script) or corountine. Every timer work for every player and i dont want dont optimized script. If you have answer, i want know him.))))

1 Like

I use task.defer() for my new thread creation. I find coroutines hard to use and cloning scripts to be not performant.

I suggest reading about the task library above if you don’t know of it, it’s pretty interesting stuff. Basically put all important thread related stuff into one big library.

Also based on what you said, I suggest task.defer instead of task.spawn, as you probably won’t need it to be activated instantly, it can probably be activated a few milliseconds later.