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

How to share global variables through LocalScripts?

I have a variable in a LocalScript that I would like to use within other scripts. However, according to the wiki, "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."

What does it mean I can use IntValue to scare data with non-local scripts? How do I do that?

1 answer

✓ Accepted answer

You cannot use _G to share information between LocalScripts on different clients, or Scripts and LocalScripts.


You can use changes to the game world, like setting NumberValue objects or other objects when those changes are replicated to other clients -- these are communicated between LocalScripts on different clients and to the server.

However, not all changes to objects are replicated. Certain objects like Messages that created by LocalScripts aren't replicated. As a consequence, their children and properties will not be shared with the Server or with other clients. In addition, if Workspace's FilteringEnabled is enabled (which it ought to be whenever possible for security reasons), then no changes replicate.

Scripts and LocalScripts can always communicate via RemoteFunctions which are secure and act similarly to functions store in _G, except that they are placed in the hierarchy of ROBLOX objects.

1 comment

0

I tried looking up and learning RemoteFunctions, but it just hurt my head. I get what you're saying though.

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