What are DataStores Prefixes?

Issue: The latest DataStores guide shows that Scopes have become a legacy. It recommends us to use Prefixes. There is no code example, which makes it hard for me to understand. Should I use " datastore name + key " to organize data now? But at the bottom of the guide, you’ll see a hint.

I don’t know how to use “/”, nor how to separate the prefixes.

I want: I would be very grateful if you could give me some code examples, or a guide link.

This is pretty simple, essentially what it is trying to tell you is that you should format your DataStore keys with some prefix for better organization so that you will have an easier time looking through specific data.

An example:

local player = game.Players.SOME_PLAYER
local userId = player.UserId

local profileToLoad = "Mage"

local dataKey = string.format("User_%s/profiles/%s", userId, profileToLoad)
local data = someDataStore:GetAsync(dataKey)

Note: string.format in this case replaces any cases of %s with the corresponding argument in order that the programmer provides.

If your game does not have multiple saves/profiles within 1 key, you do not really need to worry about this right now. If you give me an example of what you are planning to store/what your game allows a player to do regarding data, I can help you further.

1 Like

I want to give players thousands of items that can be customized. Should I store them in a key for easy access? Do you think it’s feasible to store thousands of tables in one table?

It depends on how much data you intend to store, just remember that each single key has a limit of 4 MB. This means each key can store up to 4 million characters in data.

1 Like

being purely a cosmetic workaround, that still doesn’t solve any potential problems with indexing efficiency, and it is gonna reach key length limit pretty soon