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

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

Asked by 5 years ago
Edited 5 years ago

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

Log in to vote
1
Answered by 5 years ago

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.

0
Thanks! Do you know any way I could transfer it into startergui?? User#25281 0 — 5y
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. Ashley_Phantom 372 — 5y
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. User#25281 0 — 5y
Ad

Answer this question