Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

When should values be used instead of global variables and vice versa?

Asked by 4 years ago
Edited 4 years ago

I know that Values can be used to share information between multiple different scripts. I also know that global variables can be created using _G.Variable. But I don't understand the difference between the two.

1 answer

Log in to vote
0
Answered by 4 years ago

_G exists in regular Lua normally used when interacting with the environment. Value objects however is something that Roblox made themselves to store data that lives as long as the game runs.

_G is almost never used, the only times it's normally used is when you're making some kind of library. You can use it in that case to expose a table of functions inside _G so that other scripts can call them.

This is the only advantage that _G has over value objects, the fact that they can store tables. Other than that there's no point in using _G.

Ad

Answer this question