I have two scripts, one a server script and the other a local script. I want to create a table in the server script and read it from the local script using _G. How do I do that?
Server Script (ServerScriptStorage)
_G.Inventory = { BodyTypesOwned = {"defualt", "spiky"}, BodyColorsOwned = {"2", "3"} }
Local Script (Player Gui)
for i,v in pairs(_G.Inventory["BodyTypesOwned"]) do print(i, v) end for i,v in pairs(_G.Inventory["BodyColorsOwned"]) do print(i, v) end
Instances of _G are separate to each client and the server.
You can use a remote function to read from _G on the server from the client.
Server:
RemoteFunction.OnServerInvoke = function(player, str) return _G[str] end
Client:
local tmp = RemoteFunction:InvokeServer("BodyTypesOwned") local temp2 = RemoteFunction:InvokeServer("BodyColorsOwned")