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
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!