I am getting frustrated when I am trying to learn how scopes in Roblox data stores work.
Every key in a data store has a default “global” scope, but you can further organize keys by setting a unique string as a scope for the second parameter of GetDataStore(). This automatically prepends the scope to all keys in all operations done on the data store.
The scope categorizes your data with a string and a separator with “/”, such as:
I checked out the documentation from the developer hub but I still have a lot of questions floating in my head:
Does this mean I can save individual data in different scopes? For example let’s say the player has stats, currency, and purchase records that are needed to be saved. How can I access or use scopes to organize such things?
How does DataStoreOptions.AllScopes even works with this indexing?
Any help is appreciated. You can try to explain this whole thing in your own way that could make me understand better.
When you use the AllScopes property, ListKeysAsync() returns every key with their scope as the prefix argument, such as global/player_data_1234 or houses/house3. The default scope is global.
Thanks but this still doesn’t answer the question whether or not I can save individual and different data using scopes of the data store. Because currently, my idea is that scopes allow us to save different data so that it is more organized instead of just creating a table that stores all the data in a data store’s key’s value without using scopes.
I haven’t used datastores in a long time, but I think this is how I imagined it:
(Assume the contents of the .csv files are tables, as the value. The key would be the name of the file)
You have the global scope, which contains access to all of the data to the datastore.
If we were to get the key of player_data_1234 with it’s prefix, it would return global/player_data_1234.
Let’s enter the houses scope, which contains 3 keys.
At the top, you can see the full ‘path’ to the scope (ignoring the “robloxDS”). However, when we get the keys with their prefixes, it returns houses/house1, houses/house2, houses/house3
Because the scopes would actually be structured like this