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

_G is returning nil how do I fix this?

Asked by 3 years ago

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
_G does not cross the server / client boundary. appxritixn 2235 — 3y

1 answer

Log in to vote
1
Answered by 3 years ago

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!

Ad

Answer this question