As a Roblox developer, the reusing of code is rather frustrating and time consuming in situations where you have lots of scripts and modules.
Recently I’ve found myself creating a module called ‘Library’ that holds everything from getting objects to creating and running animations.
However, to get this I am still required to go through the unsatisfying process of defining variables and going through the object tree until I can require the module.
As well as this, the module often does complex/destructive processes that shouldn’t be spammed across lots of scripts.
Finally, I am often using this ‘Library’ module to get other modules… which then require ‘Library’ again in their own code. This means I have to manually require()
the modules that get returned, instead of requiring them through ‘Library’, as that would cause infinite recursion.
Passing values directly to modules is still impossible, so there are really no other options that aren’t ‘hacky’.
Related side question
(_G
would not work because it does not load before other scripts, and would require me to setup a repeat wait()
process in every script. I also believe this topic has shown why we may not want to use it.)
Possible solution
Myself and others would much prefer it if we could create some sort of ModuleScript that we could put in a special location or give a special tag that would use globally in all of our scripts.
Not sure if this possible, though.
Another minor solution could be to allow us to toggle whether a ModuleScript returns a different instance every time it is required - or whether it loads at the start of the server and returns the exact same instance every time is required.
Solving this issue will help Roblox games to become more efficient in both performance and development. It will also encourage people to use better practices when scripting - as there are many users who still cling to old, slow and risky methods.