Efficient datastore list?

I want to get the most efficient way for a datastore list.
Datastores are known for unreliability.

I heard about Ordered Datastores but i still dont know how.

1 Like

The document for it, if you have any questions feel free to ask

For an OrderedDataStore, you must first write the data in. I’ll deliberately only use the UserId as the key here for convenience.

--We will use SetAsync, OrderedDataStores should only mimic data. No UpdateAsync is needed here.
--Setting money as an example
local store = game:GetService("DataStoreService"):GetOrderedDataStore("MoneyStore")

local function saveMoney(player:Player)
    local success, result = pcall(store.SetAsync, store, player.UserId, player.leaderstats.Money.Value)

Awesome. Now, we can get on to the part where we load it from the store.

local players = game:GetService("Players")
local ds = game:GetService("DataStoreService"):GetOrderedDataStore("MoneyStore")

--GetSortedAsync returns a DataStorePages object, with our specified page size.
local shouldReverse = false
local pageSize = 100 --100 players per page

local success, pages = pcall(ds.GetSortedAsync, ds, shouldReverse, pageSize)
if not success then warn(pages) end

--Now, we need to iterate over the first page of the leaderboard.
for rank, data in ipairs(pages:GetCurrentPage()) do
    local key = tonumber(rank.key) --player's UserId
    local saveData = data.value --the saved data
    local success, name = pcall(players.GetNameFromUserIdAsync, players, key)

    print(`Player @{name} with rank {rank} in leaderboard has {saveData} Money.`)

I hope this helps!