Is it good practice to store module script references in _G global table?

Just as the title asks, is requiring all your module scripts and storing them in the global table good practice? I’ve always seen people have different opinions on using _G. I am desynchronizing some code by duplicating scripts into multiple actors, so I guess more basically my question would be whether or not the cached reference of the module script after using require() is stored for all scripts or just each one individually. If its for all of them, I don’t care to store the reference myself, but if the cache only applies to each individual script, I’m going to store the reference in _G because I don’t want the module script being required a bunch of times

Most people would tell you to avoid using _G, simply because it makes code less portable. Like if you were to use a code library in your game that used _G, it could conflict with your usage. Likewise if you make re-usable code for someone else to use, or even for you to use in your current game and you want to use it in your next game… you have to worry about what you were sticking in _G.

You never need to use it, there is always a way to get it into a less global scope, like even if you make a singleton ModuleScript that’s just a table of globals, it’s still more encapsulated and portable than _G.

1 Like

_G shouldn’t be used unless you’re working with old code and need hacky solutions until you work on a remake (but still need to milk the old game) or you’re trying to finish the game before you hit a deadline

but on a serious project, you shouldn’t use _G nor any deprecated feature

1 Like

What would be a good solution to needing functions from a module script inside of scripts that are duplicating for parallel code purposes? It is re-requiring the module in each unique script actor. And is using script and actor duplication even a smart way to run parallel code? I’m following the example on the parallel luau documentation page.