_G for functions, is it good?

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.

1 Like