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

[Yes or no] Shared vs _G?

Hello,

I know shared and _G are almost the same, but is shared able to go client side and server side like _G cant?

-- Server side
shared.Asd = function()
	return "asd"
end

-- Client side
print(shared.Asd())

_G cannot do these things, but since shared is SO old and never been updated could it work under client and server being the same table?

1 answer

✓ Accepted answer

No. Tables can store arbitrary objects and functions. Consider this on the server:

local blah = {}

function _G.set(x)
	blah = x
end

function _G.get()
	return blah
end

I could then do this on a client:

local mine = {}
_G.get().hello = mine
mine.blah = _G.get()

Now blah, which resides in the server's memory, refers to mine, in the client's memory (and vice versa). Managing this is sort of ridiculous and doesn't make any sense. When you say _G.get(), how long do you wait? What if the value has since changed?


You have to properly use RemoteEvent and RemoteFunctions. These give a safe, simple filter that connects the client and the server.

If you really are uncomfortable using them, you can of course do some magic with modulescripts / metatables / whatever you want to take advantage of RemoteFunctions behind-the-scenes.

3 comments

0

Thank you much!

0

While it doesn't really make sense, I realized you can totally do this -- I'm writing a module script right now. (I wouldn't recommend it in practice -- it's cleaner and safer to use RemoteFunctions)

0

Nevermind, this is nightmarish (cyclic tables + functions)

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