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

_G is returning nil how do I fix this?

local script

_G.test = "hi"

server script

wait(5)
print(_G.test)

I also tried

server script

_G.test = "hi"

local script

wait(5)
print(_G.test)

Please help me fix this problem

1 comment

1

_G does not cross the server / client boundary.

1 answer

As @phxntxsmic mentioned, _G variables can only stay in the server boundary, and perhaps the client boundary, though I haven't tested the latter.

You are better off creating a StringValue in the Workspace or wherever, and reading from that in your LocalScript.

Server Script

local stuff = Instance.new("StringValue")
stuff.Name = "test"
stuff.Parent = workspace
stuff.Value = "hi"

Local Script


print(workspace:WaitForChild("test").Value) --Output: hi

If you want the client and the server to communicate with each other, I advise you to read up on RemoteEvents and RemoteFunctions.

Happy coding!

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