Questions about DataStores

Hello everyone (again)!

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.

3 Likes

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.

5 Likes

So, how is a DataStore actually created?

For example, if I made a DataStore that was called “Money,” could I add DataStores within the “Money” DataStore called “Cash” & “Gems?”

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.

For more information, you can also check this post here : Help with datastores

Also, the API pages for the service have some useful documentation as well : https://developer.roblox.com/api-reference/class/DataStoreService

Here’s an article that explains them in more detail : https://developer.roblox.com/articles/Data-store

I thought that the keys of DataStores are used to get data specific to a player? Can a key be used to get a section within a DataStore?

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:
idk
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.

2 Likes