[Still need help] How do i make a TOP 1 Global leaderboard?

  1. What do you want to achieve? Keep it simple and clear!
    So im making a game with my friend, and im trying to make a top 1 leaderboard similar to a game (i forgot the name of the game) which is displaying player with highest stat and updates (of course)

  2. What is the issue? Include screenshots / videos if possible!
    i cant im too stupid to figure out

  3. What solutions have you tried so far?
    free model global leaderboard

please make a basic code because im tired its been 2 days
EDIT: i know that full code is againsts the rules but please

2 Likes

To make a leaderboard system like this, you need to use Ordered Datastores. If you want me to provide you with a script, I can try making one. Would you like to only display the highest rank, or all the top ranks?

i know that it uses ordered datastore but it just doesnt work when im trying to make it

i said i wanted the highest stat/rank

Okay, please give me some time to make the code for you.

thanks
β€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Ž

local ds = game:GetService("DataStoreService")
local ordered_data_store = ds:GetOrderedDataStore("YOUR_DATASTORE_HERE") -- Replace it with your datastore

function GetHighestRank()
	local Pages = ordered_data_store:GetSortedAsync(false,1) -- This sorts the datastore to pages which only have 1 key.
	while true do
		wait(0.01)
		local Keys = Pages:GetCurrentPage() -- This grabs the keys of the current page.
		for i, v in pairs(Keys) do -- This will loop through all the keys of the page (in this case, it's only 1)
			return {v.key,v.value}
		end
	end
end

When you call the GetHighestRank function, it returns a table which contains the key name and value. My explanations in the script aren’t very clear, so if you want me to give you more details, I can.

1 Like

by the way can v.value has more than 1?

v.value is basically the value of the key. So yes, it can be more than 1.

and how do i do that?
β€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Ž

To change the rank integer, you need to save a new value into that datastore key. Do you want me to show you how?

okay but i have a problem
i tried to run this code and it didnt work (i edited it) i hope im doing everything right

for i,v in pairs(game:GetService("DataStoreService"):GetOrderedDataStore("I removed the datastore"):GetSortedAsync(false,1):GetCurrentPage()) do
	print({v.key,v.value})
end

I’m not sure why it’s not working. Maybe try putting things in variables.

huh?
my brain isnt working properly i forgot what variable is β€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Ž

Wait, does your datastore contain keys in it? If it doesn’t, it will not print anything since there is no highest rank.

I tested your script and it works fine. Make sure you have saved atleast one key in the datastore before using this, or else it will not return anything.

1 Like

I’ve been having a similar issue, but I know that the DataStore is not empty, and it still doesn’t print, would you be able to let me know what I could be doing wrong? (i tried to make a leaderboard)

Were you using :GetOrderedDatastore() or :GetDatastore()?

1 Like

I am using GetOrderedDataStore, I am unsure if I can send the script.

I’ve never experienced this problem, so I am unable to provide you with an answer. You can try making a seprate devforum thread so that more people can see this issue.

1 Like

I would like to make a separate thread, but I haven never done it before and recently just got permission to reply to messages. I have not the knowledge.

Update: I posted a thread

1 Like

Are you going to be able to send the script any time soon?