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

How do I use _G to read tables?

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

3 comments

0

_G are global variables

0

What do you mean?

1 answer

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

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