What I take from it is that there is no difference whatsoever in terms of speed between utilising _G or ModuleScripts, but that using _G can fall to issues with backdooring.
The only risk I see with using _G is other scripts might load before the script that assigns data to _G runs.
If you are using it on the client sure, but they can’t on the server unless you give them direct access to do so.
When people make this claim I find it strange because you can overwrite data even if you were to use modules. Basically just know what you’re doing and it’s fine. But if you could give a specific example of something like this that is an issue exclusive to _G?
If you aren’t going to write to the data again after it’s first assignment you just have to make sure the script that assigns the data runs completely before other scripts try to access _G.
I’m not really familiar with exploiters manipulating data, that information is what I gathered from the article itself, since many people mentioned it in the replies.
_G isn’t shared across the network so I don’t really see how that could be an issue. Although I kind of see what you are saying because any client can change the _G data on their device, so you just have to be careful using it on the client or only store data that affects maybe something like client settings.
Using it on the server is completely safe though; the only issue being different load times with scripts (also an issue on client).
Actually afaik, unless an exploiter can hook into the client VM (not saying this is completely impossible), _G is pretty secure.
Its 100% secure on the server.
However, you should not be using _G due to the issues of race conditions, Roblox loading order when it comes to scripts is undefined. Since _G exists on the VM stack the same way a module would, it would be much better to use a module as you can add extra functionality into the module to control when it loads
_G.Hello = "Hello World!"
print(_G.Hello) --> nil, oh no this script ran first
if you have implicit control over script loading order by encapsulating the scripts in ModuleScripts with a single loader script, since the loading order can be guaranteed, it’s safe to use _G in this case
local scripts = {
script._GVariableSetter,
script._GVariableReader
}
Another place where it’s safe to use _G is inside event handlers, since they’ll never run straight away.
If you’re setting the value of _G within a script with no yields (waits), you can safely task.wait in any other scripts to ensure that the data is set.
If you want to add an extra level of safety, you can wrap access to _G in a while loop
local scripts = _G.Scripts
while not scripts then
task.wait()
scripts = _G.Scripts
end