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

What can i use _G for?

Asked by 10 years ago

Ive seen alot of scripts with _G and i dont know whats it for can you help me?

2 answers

Log in to vote
5
Answered by
M39a9am3R 3210 Moderation Voter Community Moderator
10 years ago

You can use it for server-side script to server-side script tag values, so for instance I have _G.Tag = "Hello" in one script, and print(_G.Tag) in another script, the second script would print "Hello"

1
I didn't even know this existed thanks dude. MarkHasReset 77 — 6y
Ad
Log in to vote
1
Answered by
Vividex 162
10 years ago

A table that is shared between all scripts in one instance of Roblox. Scripts can use this to share data, including functions, between them.

Notes:

In Online mode, scripts running in a LocalScript run on the player's computer, so they are in a separate instance of Roblox and can't share data with non-local scripts except by using objects such as IntValue. In the past, this was the table that all the built-in functions were stored in, and it was possible to read values from it without writing "_G" in front. This is no longer the case.

--Script one:
_G.variable = "This a variable in _G."

--Script two:
while _G.variable == nil do wait() end --make sure that script one sets the variable before this one tries to read it
print(_G.variable)

which would become when ran:

"This a variable in _G."

Source: _G

Answer this question