How to make a global leaderboard?

My code problem

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?


1 Like

Did You Use DataStores

30char

Of course, I use DataStore, and It’s saving into datastore successfully.

So what’s the issue any error’s in the output?

There’s no errors in output, but SortedPages returns nothing for me.
Same as roblox client.

have you used

GetOrderedDataStore("DataStoreScopeHere")

Yes. I do. JustAnMoreThanThirtyCharacters

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.

Here i took this from the dev hub

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

Oh, is that real? I guess DataStore is just connected into OrderedDataStore.
Then I will try and will return a result for you.

I did it, but It doesn’t return me a datastore. just empty table.

do you actually have data stored if your data is 0 then it’ll be empty

Yes, checked it out from DataStore Editor.

I think this error happen’ cuz’ I use table to store datas.

what does the table print actaually? curious about it

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)

Maybe Off Topic But

Have You Searched Every Single Tutorial

Im Sure You Have Not Check Every Tutorial That Includes Global Leaderboards?

Here is another tutorial link

no hate please

1 Like