_G (global variabile) don't works

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

I want to know what i made wrong

  1. What is the issue? Include screenshots / videos if possible!

_G isnt global în scripts

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

Yes, and ask people but the Say it îs a global Table but Like in a script in: _G.Admins = {"HI"}

In another script: print(_G.Admins)

autput: _G.Admins is nil

There are two reasons this could happen that come to mind:

  1. You’re setting _G.Admins on a different machine to the one you’re getting _G.Admins from. Shared tables do not replicate between machines (for example the server and the client).

  2. You’re getting _G.Admins before you’re setting _G.Admins. The scripts might be running in the wrong order. You can add a wait() before getting the table in the appropriate script to test this more accurately.

1 Like

Ok, and no i dont use from server to client

A common way to wait for a _G key to register is by creating a while loop. It prevents code from running until your _G table has been registered.

while not _G.Admins do
    wait()
end

You see though, this is strange. That and you should typically try to avoid using _G, especially if you don’t add a namespace for your script there. Other scripts may be attempting to use _G and you don’t want to rely on pointless looping like this. This could get messy if you need to wait for multiple items to register as well.

You should look into ModuleScripts that return your list of admins and other admin configuration values over using _G.

5 Likes