Ordered Datastores returning an empty dictionary

I’m trying to make a leaderboard system, but for some reason it isn’t working. I have printed entries and it returns an empty dictionary, so I think it has to do with retrieving credits.

local datastore = game:GetService("DataStoreService")
local playerCredits = datastore:GetOrderedDataStore("credits")

local pages = playerCredits:GetSortedAsync(false, 25)
local entries = pages:GetCurrentPage()

for index, entry in pairs(entries) do
	print(index .. "-" .. entry.key .. "-" .. entry.value)
end

Hey. Have you tried running it in game and made sure you have anything actually saved in ‘credits’?

I tried to run the code in the terminal, adding a print statement that will print entries, but it still returns an empty table.

I believe studio will not let you do as such. Are you sure you have data within that table? Do you have API services enabled?

Yes. I have already implemented datastores into my game, and they are working fine.

going back to @4kdvn’s previous, unanswered question, is there anything saved in the credits OrderedDataStore? It’s important to note that OrderedDataStores are separate from standard DataStores.

No… Do I have to save credits into OrderedDataStore?

Yes; OrderedDataStores are separate to DataStores. Don’t bother putting as much security when saving it, a simple SetAsync in a pcall should work as it’s only meant to mimic already existing data.

Save to the ordered data store as well when you save data normally.

2 Likes