Leaderboards randomly stopped working - displaying 2 names

  1. What do you want to achieve? Keep it simple and clear!
    I want to find a way to fix the leaderboards to have them display all data.

  2. What is the issue? Include screenshots / videos if possible!


    In the leaderstats, you can see that I have 19 kills and 5,700 highest time. If you look at the kills leaderboard, there’s nothing displayed even though you can see my kills. Previously when these were working, there were around 15 names listed on both leaderboards. Now, there are two names listed on the “Most Time” leaderboard and none on the most kills.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I haven’t tried much since I couldn’t find any similar issues to mine. There are 0 errors in the output relating to leaderboards.

Here are the scripts inside of the leaderboards, datastore script is somewhere else. If you need the DSS script please let me know.

Kills LB script:

local DataStore = game:GetService('DataStoreService')
local OrderedDataStore = DataStore:GetOrderedDataStore('KillsLB2')
local cache = require(game.ServerScriptService["Server/Data"].ProfileCacher)

local refreshTime = 2

local ResetTimer = script.Parent.Parent.ResetTimer

while true do
	wait(1)
	refreshTime -= 1
	ResetTimer.Text = "Leaderboard refreshes in " .. refreshTime .. " seconds!"

	if refreshTime == 0 then
		refreshTime = 60

		for index, plr in pairs(game.Players:GetChildren()) do
			local profile = cache[plr]
			if profile ~= nil then
				OrderedDataStore:SetAsync(plr.UserId, profile.Data.Kills)
			end
		end

		for index, list in pairs(script.Parent:GetChildren()) do
			if list.ClassName == 'Frame' then
				list:Destroy()
			end
		end

		local success, errorMessage = pcall(function()

			local data = OrderedDataStore:GetSortedAsync(false, 40)
			local currentPage = data:GetCurrentPage()

			for currentRank, storedData in ipairs(currentPage) do

				local name = game.Players:GetNameFromUserIdAsync(tonumber(storedData.key))
				local time = storedData.value

				local cloneList = script.Template:Clone()
				cloneList.Name = name .. " 's leaderboard rank"
				cloneList.Username.Text = name
				cloneList.Rank.Text = currentRank
		
				cloneList.Amount.Text = time
				cloneList.Parent = script.Parent


			end
		end)
	end
end

Time LB script:

local DataStore = game:GetService'DataStoreService'
local OrderedDataStore = DataStore:GetOrderedDataStore('KillsLB1')
local cache = require(game.ServerScriptService["Server/Data"].ProfileCacher)

local refreshTime = 2

local ResetTimer = script.Parent.Parent.ResetTimer

while true do
	wait(1)
	refreshTime -= 1
	ResetTimer.Text = "Leaderboard refreshes in " .. refreshTime .. " seconds!"

	if refreshTime == 0 then
		refreshTime = 60

		for index, plr in pairs(game.Players:GetChildren()) do
			local profile = cache[plr]
			if profile ~= nil then
				OrderedDataStore:SetAsync(plr.UserId, profile.Data.HighestTime)
			end
		end

		for index, list in pairs(script.Parent:GetChildren()) do
			if list.ClassName == 'Frame' then
				list:Destroy()
			end
		end

		local success, errorMessage = pcall(function()

			local data = OrderedDataStore:GetSortedAsync(false, 100)
			local currentPage = data:GetCurrentPage()

			for currentRank, storedData in ipairs(currentPage) do

				local name = game.Players:GetNameFromUserIdAsync(tonumber(storedData.key))
				local time = storedData.value

				local cloneList = script.Template:Clone()
				cloneList.Name = name .. " 's leaderboard rank"
				cloneList.Username.Text = name
				cloneList.Rank.Text = currentRank
		
				cloneList.Amount.Text = time
				cloneList.Parent = script.Parent


			end
		end)
	end
end

Thanks!

The reason there are no errors because your using a pcall function, you need to print them out yourself:
Put this after the pcall function

if not succss then 
    print(errorMessage) 
end

Thank you for this, now I know where the problem is but still not why it’s happening. The error is “Players:GetUserIdFromNameAsync() failed: Unknown user”

I’m going to try to do some additional research on how to solve this, if you have any suggestions please let me know.

Thank you for the feedback, but I’m still really confused what’s going wrong here. The leaderboard is now showing more than 1 person per board, but it’s still missing some.


(keep in mind I only added the checks you suggested to one LB)

If you look closely to where its breaking, it’s doing so at -2 which I’m fairly sure that the storedData.key shouldn’t be -2 find that issue and resolve it. Nevertheless, I’m confused as the code seems to be working, what exactly isn’t being loaded do you have an example of all the players you should print out the entire current page to see what exactly it’s reaching and why it’s result is not matching your logic.

EDIT: I would say starting above local name add a pcall and in the error message print(storedData).
Note: when u do this u can easily see what data is erroring which player and look at their name id and all of that stuff

dataSucess, dataError = pcall(function()
        local name = game.Players:GetNameFromUserIdAsync(tonumber(storedData.key))
        if not name then return end
        local time = storedData.value

        local cloneList = script.Template:Clone()
        cloneList.Name = name .. "'s leaderboard rank"
        cloneList.Username.Text = name
        cloneList.Rank.Text = currentRank
        cloneList.Amount.Text = time
        cloneList.Parent = script.Parent
end)
if dataError then warn('Error With', storedData) end

Previously, there were around 16 players on the leaderboard. Suddenly when I joined one time, nearly all of the players were no longer displayed on the leaderboard. I believe it’s not a datastore issue as one of the players not displayed on the leaderboard still has their proper leaderstats.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.