How would I create multiple global leaderboards?

I am able to make a single leaderboard just fine but cant for the life of me figure out the best way to make multipler global leaderboards. my only thought is using multiple ordered data stores but that seems it would fill up the queue too fast. Any ideas?

1 Like

Based on the datastore limits, retrieving multiple datastores shouldn’t be a problem, plus getting a sorted async won’t be a problem as long as this limit applies to your game:


As long as you’re not calling GetSortedAsync() more than 5 + numPlayer x 2 times per minute, you should be fine.

3 Likes

Here’s how I do it :

	local success, err = pcall(function()
					CoinsOrderedData:SetAsync(PlayerUserId, statsTable.TotalCoins)
					GemsOrderedData:SetAsync(PlayerUserId, statsTable.Gems)
					EggsOrderedData:SetAsync(PlayerUserId, statsTable["Eggs Hatched"])
				end)
				if not success then
					warn("Saving leaderboard data wasn't succesfully executed.")
				else
					print("Saved leaderboards")
				end

Note : That’s not my total script but this is the part where im setting the values in the ordered datastore.

For the orderedstore, I recommend you doing this :

local Currency1OrderedData, Currency2OrderedData, Currency3OrderedData = DataStoreService:GetOrderedDataStore("Leaderboard", "Currency1"), DataStoreService:GetOrderedDataStore("Leaderboard", "Currency2"), DataStoreService:GetOrderedDataStore("Leaderboard", "Currency3")

I don’t know if this is a safe method. “:SetAsync()” as listed in the limits table should only be called once per six seconds since it’s a written async, so this could lead to data loss or no save at all, unless I’m wrong

I’m calling it one time per orderedstore each 30 seconds. Its a while true do, loop through players and set async their values.

Oh, so you can call :SetAsync() 3 times in 30 seconds? like, you can call “:SetAsync()” 3 times in a go and still save everything?

Hmm, actually, it works out for me perfectly so i guess yea?

Thanks, I guess It was just my previous datastore PTSD acting up. Thanks for the solution :grin: