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

How to have global variables from workspace go into StarterGui??

So I have a variable, _G.have. How do I make this global variable appear in my StarterGui code?? Code in starter:

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

mouse.Button2Down:Connect(function()
	print(_G.have)
		if _G.have == true then
			player.Character.Weld:Destroy() --ignore these
			_G.have = false
	end
end)

It just prints nil, can someone please tell me how to make global variables in starterGui???

1 answer

✓ Accepted answer

Hi there, before I begin I want to apologize for my minimal brain activity, it's 02:27 here, anyways,

_G is what's known as a global table, what matters is that it's not very global the way we use it, it depends on the lua state and other stuff, all you need to know is:

_G does not transfer between scripts with different context values, and in your case, the main problem, is that _G does not transfer between the server and client, you cannot use it for server-client variable transferring.

3 comments

0

Thanks! Do you know any way I could transfer it into startergui??

0

Easiest way is to of course just create a NumberValue / StringValue / ObjectValue or whatever you want from the server side, then the scripts in the client can interact with them, in a read only mode, of course, if the client makes any modifications to it, it will not replicate, if you want it to, you can use a RemoteEvent and a handler.

0

Alright, I was trying to do that before but t didn't work, I think I just made a simple error. I will try again.

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