Hello! I’m making a game, and I wanted to add the experience global leaderboard in my game.
Yes, DataStore is working completely, it returns correct datas.
so I used some YouTuber for references, and I made it. but It doesn’t work.
Just like no errors, but no returns. I checked it up the datas, and I found it that I am saving data using array. just like {1, 2, 3}. I’m too lazy to turn those things to number and contain it, but It doesn’t still work.
my GetSortedAsync’s option was like that:GetSortedAsync(true, 15)
and returned array with empty. what’s going on with it?
TL;DR
I make global leaderboard, and it requires sorted datastore.
I’m saving datas using array, and I guess It’s not so easy to sort it. so they didn’t returned.
how do I do?
From my experience, you not only have to load data onto a leaderboard with OrderedDataStores, but you also have to save data to the same OrderedDataStore as well, not just a regular DataStore.
local dataService = game:GetService("DataStoreService")
local dataStore = dataService:GetDataStore("Data")
dataStore:SetAsync("taco", 300)
Using this code example above, the OrderedDataStore “Data” does not have any data, because we didn’t save it to an OrderedDataStore.
local dataService = game:GetService("DataStoreService")
local dataStore = dataService:GetOrderedDataStore("Data") --Notice the difference here?
dataStore:SetAsync("taco", 300)
This example would load it to a leaderboard, since we save data to an OrderedDataStore.
See what I’m trying to say? You have to save data to an OrderedDataStore to display it on a leaderboard.
local DataStoreService = game:GetService("DataStoreService")
local characterAgeStore = DataStoreService:GetOrderedDataStore("CharacterAges")
-- Populate ordered data store
characterAgeStore:SetAsync("Mars", 19)
characterAgeStore:SetAsync("Janus", 20)
characterAgeStore:SetAsync("Diana", 18)
characterAgeStore:SetAsync("Venus", 25)
characterAgeStore:SetAsync("Neptune", 62)
-- Sort data into pages of three entries (descending order)
local pages = characterAgeStore:GetSortedAsync(false, 3)
while true do
-- Get the current (first) page
local data = pages:GetCurrentPage()
-- Iterate through all key-value pairs on page
for _, entry in pairs(data) do
print(entry.key .. ":" .. tostring(entry.value))
end
-- Check if last page has been reached
if pages.IsFinished then
break
else
print("----------------")
-- Advance to next page
pages:AdvanceToNextPageAsync()
end
end
this is some advice in order to make your own leaderboard
My Windows 10’s clipboard aren’t working for some crappy reason, but It actually returns the accurate data, since It appears on my GUI (just like levels, moneys)