I have a variable in my script editor called "_G" but i don't know how to use it so i tried this :
1 | print (_G) |
but the output says :
1 | table: 1 C 06 E 8 EC |
It is a table ? I need to understand how "_G" works
_G is a shared table. Accessible through all scripts in the game
_G.NAME_OF_VARIABLE = "VALUE"
e.g
_G.StringThatSaysHi = "Hi"
For a better visualization, think of it as a regular table
1 | local myFruits = { } |
2 | myFruits.Apples = 2 |
3 | myFruits.Bananas = 3 |
_G is a global table that is accessible from all scripts of its kind. The server and every client has their own _G table. You can't use it as your own variable because the script will think that you're referencing the table.
If you wanted to make use of _G, you could store a variable or function from one script and quickly pass it to another, like this:
Server Script #1
1 | _G.Money = 40 |
Server Script #2
1 | print (_G.Money) |
2 | -- prints 40 |