Is there a way to use _G in a local script?

Hello there, So basically i just wanna know how i could use _G in a local script… heres an example of what ive been trying todo:
serverscript inside ServerScriptService:

_G.key1 = workspace.Value1.Value

in the local script:

if _G.key1 == "10" then
print("Working")

end

(BTW this is an example of my scripts… i dont wanna leak my actual scripts so i figured if i learned how todo this it would fix my issue)

You should refrain from using _G and instead look towards implementing ModuleScripts in your project.

7 Likes

You can use _G locally. However _G on the server and _G on the client are different tables. Every client has their own _G table.

You can’t simply set _G.someValue on the server and then try to read it from the client. You need a remote event or remote function to cross the client server barrier.

2 Likes

You can use _G locally or on the server, but they’ll be separate tables. RemoteEvents/Functions should be used to share values between the client and the server.

how would i be able to use a remote event as a replacement for _G.key1?

Couldn’t you just do

if workspace.Value1.Value == "10" then
print("Working")

end

Also please put your script here so we could decide which solution would be best? Also, no one will ever care about using your “leaked script” in their game.

2 Likes

XY problem

From Wikipedia, the free encyclopedia

The XY problem is a communication problem encountered in help desk and similar situations in which the person asking for help obscures the real issue, X , because instead of asking directly about issue X , they ask how to solve a secondary issue, Y , which they believe will allow them to resolve issue X . However, resolving issue Y often does not resolve issue X , or is a poor way to resolve it, and the obscuring of the real issue and the introduction of the potentially strange secondary issue can lead to the person trying to help having unnecessary difficulties in communication and/or offering poor solutions.

The XY problem is commonly encountered in technical support or customer service environments where the end user has attempted to solve the problem on their own, and misunderstands the real nature of the problem, believing that their real problem X has already been solved, except for some small detail Y in their solution. The inability of the support personnel to resolve their real problem or to understand the nature of their inquiry may cause the end user to become frustrated. The situation can make itself clear if the end user asks about some seemingly inane detail which is disconnected from any useful end goal. The solution for the support personnel is to ask probing questions as to why the information is needed, in order to identify the root problem and redirect the end user away from an unproductive path of inquiry.

1 Like

you could probably use remote functions to get info from serverside _G to a local script

Remote events or remote functions will be your new best friend!

1 Like

That’s terrible advice. _G is extremely useful when following the don’t repeat yourself rule. While you should never handle an anti-exploit within a local script, cosmetic functions are perfectly safe to be stored there.

3 Likes

I see so many people saying this but I never get an explanation as to why I shouldn’t use it. Why shouldn’t I?

1 Like

at 1st, can i ask you a question?

Why the hell are you using _G when you can just use module scripts?

_G was used before module scripts were a thing, and you can tell, it isnt really safe to use.

Just start using module scripts, they are way better at any aspect than _G.

whoops, didnt see it was a bumped up post.