Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Scripts and Thread Efficiency?

Let's say I'm trying to create an RPG world with numerous near-identical monsters. In the case of AI, would it be more efficient to have a script per monster or a single script somewhere else that handles all of them abstractly, but in a multi-threaded fashion?

For sake of passing the not-a-question filter: r.Stepped:connect(function() --Do AI stoof end)

tl;dr: Single multi-threaded script or multiple single-threaded scripts?

Also, is it more proper to refer to them as coroutines or threads?

2 answers

✓ Accepted answer

The most efficient way would most likely be a single thread for all the monsters. However, for this question I suspect that multiple coroutines would likely be faster (as multiple scripts will run on multiple threads, anyway, and have different global environments and require the actual Script object)

1 comment

0

Thank you for your input, I forgot to take into account the script itself.

I'm thinking a good way would be having a ModuleScript in each monster and have one base script to control all of the monsters in case you want some monsters to have different AI as different monsters but have the same basic functions.

2 comments

0

Neat idea! I'll be sure to do that!

0

I thought about doing this, but was not sure if the source would replicate (and thus be under threat of theft.) Of course, a ModuleScript which requires a ModuleScript in ServerScriptService/ServerStorage is safer.

This discussion is preserved as it was. New answers, comments, and votes are closed.