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

How do I use _G to read tables?

Asked by 4 years ago

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
0
_G are global variables JesseSong 3916 — 4y
0
What do you mean? VexTrexYT 28 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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")
Ad

Answer this question