How to properly use ModuleScripts?

I’m not asking how you use ModuleScripts. I’ve already looked this issue up, but the thread I found did not answer my question.

I always find myself requiring Modules that require itself, resulting in infinite yielding. So I’m asking how do I properly use ModuleScripts?

1 Like

Just don’t have the module require itself. Beyond that, use it for whatever you find it useful for.

1 Like

Yep like @AljoSven just don’t do that. But the more in depth answer is a lot more complicated and falls under code paradigms or code organization. This has been discussed previously in this thread.

TL;DR from my experiences use module scripts to “repeat code” well it’s said right there in the documentation for ModuleScript | Roblox Creator Documentation as the DRY principle but in the specific following ways:

  1. Repeated functions, like a python libary

  2. Storing properties within a table like configurable settings.

  3. As an OOP class to repeat properties and functions.

  4. Sharing tables between scripts in the same environment local/server to share variables.

  5. Personally, currently using ECS so the module scripts represent systems and components that can be accessed by different scripts.

  6. Glorified normal scripts in order execute the code in a certain order like in Aero Game Framework and gurantee which code runs first to set things up like remote events.

  7. Perhaps a lot more than I can think of right now check out #resources:community-resources for more uses of module scripts like game frameworks and such.

1 Like