Hello there!
To make work easier I want to store all modules somewhere to easily access them without writing these long lines. But I heard that using _G is a bad idea and you shouldn’t use global variables at all. So, is storing a list of all modules in a list as a global variable a good idea or there’s a better option?
Absolutely not, what i did was i simply made a module to always require and inside the module i added a function to easily get other modules, of course this is only how i did it and it may not work for you.
local module = require(ReplicatedStorage.Module)
local otherModule = module:GetModule("OtherModule")
local someClass = module:GetModule("SomeClass")
The problem with making something global is that your essentially giving everything access to it.
And this could make debugging later down the line more difficult as you may struggle to find what is changing what.
I’d recommend just requiring modules only in scripts that require that specific resource.
But it really depends on how you want to approach things and your workflow.
Thanks for answers! I think I’ll do a single module with a for loop
I was thinking more that an exploiter could then easily access everything without having to do something too hacky like digging through memory or abusing namecall metamethods. But, maybe they won’t think to look in _G
or shared
.
I think this is a good thing, if you ignore the exploiters.
I agree that maybe it would make debugging harder. But at the same time, you can make great modular systems for a lot of creative freedom. Therefore, debugging becomes easier again.
You probably shouldn’t use globals solely to make it more difficult for exploiters. -A bit off-topic but there are likely more effective techniques such as obfuscation (but at what cost?).
Completely agree, I mean if you can use them correctly and it works for you then sure why not?
It’s definitely one of them debatable things in programming were some people love to use them and others hate them.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.