I have a couple questions about Data Stores. I was reading through the Roblox Developer Page (again) as I’m trying to implement Data Stores in my game and I’m a bit confused about Data hierarchy. My main questions are:
Is there a function for creating data stores? Or are data stores created when you call the SetAsync() functtion?
How do GlobalDataStores differ from plain DataStores?
Can DataStores be saved into DataStores?
Btw, thanks to anyone that has helped me in learning the Roblox Studio.
The DataStore is what is returned by DataStoreService:GetDataStore(). Functions like SetAsync() and GetAsync() require the key argument, under which the data is stored. If there is no data stored under the certain key, GetAsync() will return nil.
GlobalDataStore is what you would call a “plain DataStore”. That is what DataStoreService:GetDataStore() returns.
The other type of DataStores is OrderedDataStore which is returned by GetOrderedDataStore.
Not sure what you mean. If you mean the instance then no, instances and custom data types cannot be stored in data stores. Only simple data such as tables, numbers and strings can be saved.
Then the DataStore would be called Money and the keys Cash and Gems.
Picture it as “sections” of the DataStore. One would prefer to have i.e. Admins, Bans and Logs under the same DataStore, but in different areas of it. Creating a separate DataStore each time woule be pointless, especially when it comes to stuff such as storing every player’s data under a key made of their UserId.
A DataStore is just a container for your data. In order to store a data in it, you need to assign it to some key.
Since I’m finally on PC, I made a nice visualization in paint:
As you can see, you cannot just throw your data at the DataStore. You need to put it under a key. The key can be any string you want. It’s just better and more effective than having to make a new DataStore each time.