Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

LocalPlayer Global Variables?

I'm just wondering, would each player each have their own different _G variables?

For example,

PLAYER A:

_G.foo = 123
print(_G.foo) >> 123

PLAYER B:

print(_G.foo) >>> 123?

^^ Or would this player have to set _G.foo in a localplayer script to print something?

Sorry if the question seems hard to understand, I don't completely understand _G variables and I'm not sure how to put this question!

Thanks!

2 answers

✓ Accepted answer

Good question.

What is _G?

The built-in _G variable represents a table. This table is saved on either the server, or a local script running on an individual's computer (depending on if you're using a local script, or a server script).

Like all tables, we can read and write data to it by indexing it with either brackets [ ], or a period .

Server-sided

On the server, the_G table is shared throughout all server scripts, no matter their location. However, like everything else, this is entirely separate from local scripts, as local scripts run on the individual's computer. Not the server.

Client-sided

Client-sided is a different story. Remember, since local scripts run on an individuals computer, the data is not automatically replicated to all clients. Just the individual. You can think of it as each individual player being their own server in that perspective.

Answers?

To answer you question specifically, yes. Each player does have their own _G, but ONLY IF it's being stored in a local script. Remember, server scripts have access to the server at all times, no matter where they are. Placing a server script inside a player will not make it local.

Hope this helped, if you have any questions, let me know.

1 comment

0

Thank you! :)

Global variables are GLOBAL, as in it works together with all clients and the server. You can read and write global variables with both Local Scripts and Server scripts.

However, I don't believe you can write server variables locally when FilteringEnabled is turned on. LocalScripts can still read them.

Hope this helped!

2 comments

0

Actually this is a bit inaccurate, sorry.

0

Sorry, I like putting things in a simple manner for some people and a few times is generates innacuracies.

This discussion is preserved as it was. New answers, comments, and votes are closed.