Don't understand the _G

_G Can be used for Global Variables/Arrays. You can learn more about it at Lua Globals (It is at the bottom of the Page)

For example, You can declare the Variable at a certain script:

-- First script
_G.MyName = "Crunch"

And use it on another one! It’s recommended to yield (wait) for a small time as it may take a very small amount of time to be accessed.

-- Second Script
task.wait()
print(_G.MyName)

Using Global Variables (_G or shared) for holding/storing Data (or even manage it) is not the best idea. I recommend you taking a look at ModuleScripts to understand more about them, And if you’re looking towards saving data, I recommend you using ProfileService.

3 Likes