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

Help with _G?

Asked by 8 years ago

I have 2 scripts, one a ServerScript inside ServerScriptService and the other a LocalScript inside the StarterGui.

ServerScript

_G.actor = 1
print(_G.actor)

prints '1' in the output of the server

LocalScript

print(_G.actor)

prints 'nil' in the output of the client

I want it to print '1' the output of the client as well as the server.

I have tried turning the LocalScript into a ServerScript, but I have an event, which needs to fire an OnClientEvent, so it has to be a LocalScript. Is their a way to make it work?

  • NinjoOnline

1 answer

Log in to vote
2
Answered by
Validark 1580 Snack Break Moderation Voter
8 years ago

Roblox Wiki: "A global function is a function which is present in _G, also known as the global table. The same _G is accessible from any script, so putting a function in _G allows any script to call the function.

Keep in mind that the server has a different _G than clients do, so you can't define a global function in a server script and then use it from a LocalScript.

You may want to consider using BindableFunctions and BindableEvents instead of global functions. If you need to communicate from client to server or server to client, then you should use RemoteFunctions and RemoteEvents."

Ad

Answer this question