Global ranking system?

In my game, I thought it would be cool if there was a global ranking system (I.E. player joins and it says they are ranked number 3,713 out of 11,938 players). I’ve never seen a Roblox game do this before, I read some datastore documentation but I can’t find anything. If anyone can point me in the right direction please do.

What would the ranking be based off of? A certain stat? As you have stated it wouldn’t be possible to rank anyone without a reason to rank them. Also you will need to store the data so it can choose to rank the player based on their stats.

Yeah sorry I forgot to mention that. My game stores an int value of kills into a datastore.

So basically if you are already have a stat, you’ll need to store that data in a datastore and have it accessed by a script that will determine the rank of the player just as if you had a global leaderboard in your game. The best way to display this would be a BillboardGui inside the players Head, you just clone it via a script.

That doesn’t really help me, you kind of just restated what I originally said.

1 Like

I think this would work but idk about how efficient it is:

local ds = game:GetService("DataStoreService"):GetOrderedDataStore("V.1")



function loopthrough(userId) -- userid being the userid of the player you wanan find the rank of
	local max = 10 -- max players per page
	
	local pages = ds:GetSortedAsync(false,max,1)

	

	
	local userspot
	local pageNumber
	
	local pagecounter = 0 -- A variable to count the total pages
	
	repeat 
		task.wait()
		local cpage = pages:GetCurrentPage()-- gets the current page
		

		for rank, data in pairs(cpage) do--loops through current page
			if data.key == userId then -- assuming your key's are the player's userids
				userspot = rank -- records their exact rank on the page
				pageNumber = pagecounter--records the page the specific user was on.
			end
		end
		
		pagecounter += 1

		
		pages:AdvanceToNextPageAsync()
		
	until pages.IsFinished -- check if we iterated through all possible pages
	
	local MaxRanks = max * pagecounter -- Total values .This is rounded to the nearest 10th so in certain scenarios, this will not be accurate. Edit the code to make it exact
	
	local playerRank = pageNumber * max + userspot-- gets their spot out of all the values. If they are in the top ten it would be equal to: 0 * 10 + theirrank. 
	
	print(playerRank.."/"..MaxRanks)
end

I did not test the code so there is bound to be errors or math issues but hopefully it gives you an idea. There is probably a more efficient way to do this.

https://developer.roblox.com/en-us/api-reference/class/DataStorePages
https://developer.roblox.com/en-us/api-reference/class/OrderedDataStore

I’m simply trying to point you in the right direction as you previously said. I am giving you exact instructions on how you can accomplish your goal. This isn’t a space to ask for others to do your work for you. If I were you, I’d refer to the developer page on roblox about datastores. Assuming you have experience in studio, you’ll be able to setup the Gui and write it all out yourself.

You could also consider using HTTPService and hosting a site that can be polled for the current leaderboards.

https://developer.roblox.com/en-us/api-reference/function/DataStoreService/GetOrderedDataStore