✓ Accepted answer
To answer your question directly, yes. You can technically use _G. To answer the more important question of whether or not you should, not really.
First, any server script is allowed to check DataStore. You don't need _G for that (though you also shouldn't constantly send get requests or overwrite existing data, you'll get throttled.)
You should use module scripts. Use module scripts both to easily check and set data in the DataStore, and to have server-side variables that can be checked and modified from other scripts. _G isn't necessary here, and this isn't the best application for it. It's often regarded as a poor practice today. (A lazy solution is to use value objects, but I don't recommend them.)
You might be interested in the following pages:
ModuleScripts
Data Store
Saving Player Data
These pages provide both examples and descriptions which should help you.
7 comments
while you can, i dont suggest it, instead use only 1 script that takes care of the data and sends it to other scripts through remote/bindable events/functions.
and thats not how you get a player's data
really don't do that @xMonaitary. Use modules or what radusavin366 said
Yes you can ,but you don't need _G. Your datastore can be accessed in multiple scripts, even in places within the same game universe, by just doing the same thing in the other script - you'll get the datastore with the same name.
Oh, well I knew that, I just thought this would be easier, thanks.
And @radusavin366, I was using folders and string values as the player's data. @incapaz, I have absolute no idea how to correctly use dictionaries.. in a module especially.
That's not how to save/store data, and while dictionaries are useful (especially when you have a lot of data), they're not needed for datastore. Using them in a module is no different. Make a function in a module that gets data, and one that sets data. Make a server-side copy of the data if you really want to & only save when the player chooses / when they leave if you're worried about throttlle