local script
1 | _G.test = "hi" |
server script
1 | wait( 5 ) |
2 | print (_G.test) |
I also tried
server script
1 | _G.test = "hi" |
local script
1 | wait( 5 ) |
2 | print (_G.test) |
Please help me fix this problem
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
1 | local stuff = Instance.new( "StringValue" ) |
2 | stuff.Name = "test" |
3 | stuff.Parent = workspace |
4 | stuff.Value = "hi" |
Local Script
1 | 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!