@TintinHenryBest (Henry) posted a new topic, subject "Using _G.variable". It read:

   I need a server variable that will NEVER, EVER change, is using _G a good idea?

After which, @camomileex0 (camomileex0) added

    _G or `shared` will work fine. Note that this will reset on each server (which makes sense)

Then @Benified4Life (Sekonds) said

    I wouldn't recommend using _G. Firstly, lets use 2 scripts as an example. ScriptA is currently setting a global variable called bananas, and lets say it's value is 50. This also has other code in it and took 1 second to run (emphasised for ease of reading). Now, ScriptB is trying to access that same variable but only takes 0.5 seconds to run. This means that it'll error for ScriptB, as it tried to access it before it came into existance, returning nil.
    
    A “fix” for this would be to yield each script accessing that variable, but this is just a hacky fix which would suck for big games.
    
    Shared is also just bad practice so I recommend using InstanceValues, modules, etc.

So @R0bl0x10501050 (R0bl0x10501050) replied

    **Do you need it between scripts?**
    
    Yes → Store it in an Attribute / [TYPE]Value Instance  
    No → Initialize it as a top-level variable at the top of the script you want to access it in

To which @Pokemoncraft5290 (Based) replied

    R0bl0x10501050:
    
    > Yes → Store it in an Attribute / Value Instance
    
    Or if it's a table of values and you don't want to create a bunch of individual value objects, use a module script.

Then @R0bl0x10501050 (R0bl0x10501050) said

    Using Attributes is probably better than both [TYPE]Values and ModuleScripts because those are extra Instances and take up far more memory than a single Attribute.


{'source': 'discourse', 'url': 'https://devforum.roblox.com/t/using-gvariable/1456059', 'title': 'Using _G.variable', 'views': 292, 'has_accepted_answer': False, 'word_count': 260, 'like_count': 2, 'reply_count': 2, 'participant_count': 5, 'posts': 6, 'tags': '', 'author': '@TintinHenryBest (Henry)', 'participants': '@TintinHenryBest (Henry), @camomileex0 (camomileex0), @Benified4Life (Sekonds), @R0bl0x10501050 (R0bl0x10501050), @Pokemoncraft5290 (Based)', 'image_url': [None], 'created_at': '2021-09-05T23:17:03.718Z', 'last_posted_at': '2021-09-06T03:42:20.002Z'}