Problem with global leaderboard

Hi! I was following a global leaderboard tutorial by devking but It isn’t working. I have some scripting knowledge and I can’t see any mistakes. I’m actually losing my mind reading my code about 30 times.
Through debugging I found that “robuxPage” just has no value. its just an empty table. Any ideas why?

local dss = game:GetService("DataStoreService")
local robuxLeaderboard = dss:GetOrderedDataStore("RobuxLeaderboard")

local function updateLeaderboard()
	local success, errorMsg = pcall(function()
		local Data = robuxLeaderboard:GetSortedAsync(false, 5, 9.22e+17)
		local robuxPage = Data:GetCurrentPage()
		print(robuxPage)
		for rank, data in ipairs(robuxPage) do
			local userName = game.Players:GetNameFromUserIdAsync(tonumber(data.key))
			local name = userName
			local robux = data.Value
			local isOnLeaderboard = false
			for i, v in pairs(game.Workspace.RobuxLeaderboard.LearderboardGUI.Holder:GetChildren()) do
				if v.Player.Text == name then
					isOnLeaderboard = true
					break
				end
			end
			
			if robux and isOnLeaderboard == false then
				local newLbFrame = game.ReplicatedStorage:WaitForChild("LeaderboardFrame"):Clone()
				newLbFrame.Player.Text = name
				newLbFrame.Robux.Text = robux
				newLbFrame.Rank.Text = "#" .. rank
				newLbFrame.Position = UDim2.new(0,0, newLbFrame.Position.Y.Scale + (.08 * #game.Workspace.RobuxLeaderboard.LearderboardGUI.Holder:GetChildren()), 0)
				newLbFrame.Parent = game.Workspace.RobuxLeaderboard.LearderboardGUI.Holder
			end
		end
	end)
	
	if not success then 
		warn(errorMsg) 
	end
end

while true do
	for _, plr in pairs(game.Players:GetPlayers()) do
		robuxLeaderboard:SetAsync(plr.UserId, plr.leaderstats["Robux Spent"].Value)
	end
	
	for _, frame in pairs(game.Workspace.RobuxLeaderboard.LearderboardGUI.Holder:GetChildren()) do
		frame:Destroy()
	end
	
	updateLeaderboard()
	print("Updated!")
	
	task.wait(10)
end
1 Like

How is it not working, what’s going wrong? It could be a thing with studio being weird with datastores, you can check if it works in an actual game by putting publicity to private and trying your own game, and if thats not the case you should check if roblox can even access datastore within some setting (I think it might be under the security tab) within your game settings on studio. Reply to me if it’s not to do with these 2 things

I already tried in the actual game. I also have enabled api services. The frame never gets cloned. I put a print inside

if robux and isOnLeaderboard == false then
				local newLbFrame = game.ReplicatedStorage:WaitForChild("LeaderboardFrame"):Clone()
				newLbFrame.Player.Text = name
				newLbFrame.Robux.Text = robux
				newLbFrame.Rank.Text = "#" .. rank
				newLbFrame.Position = UDim2.new(0,0, newLbFrame.Position.Y.Scale + (.08 * #game.Workspace.RobuxLeaderboard.LearderboardGUI.Holder:GetChildren()), 0)
				newLbFrame.Parent = game.Workspace.RobuxLeaderboard.LearderboardGUI.Holder
			end

and it never ran. isOnLeaderboard == false (i tested this) so it must me robux that is nil.

(as far as i know, the rest of the script works)

In the part of the script where it says

local Data = robuxLeaderboard:GetSortedAsync(false, 5, 9.22e+17)

the second argument, 5, is the minimum number, if the Robux you’ve spent isn’t more than 5, it wont appear on the leaderboard. I’m not sure how your testing the leaderboard but this could be what the problem is.

Try making the argument 0

1 Like

image
I get this error. I spent more than 5 anyway.

go through devking’s tutorial again and see the problems you might have missed something

1 Like

Looking at the documentation for ordered datastores the first argument is the order, the second is the page size, the third the minimum value, and the fourth being the maximum value. Try changing the second argument to a number between 50-100

local Data = robuxLeaderboard:GetSortedAsync(false, 50, 5)
1 Like

Okay, so im not entirely sure if i was just being stupid and copied it down wrong from the tutorial, but after I changed it to your solution it worked so I’m going to mark that as the solution. thanks for your help

1 Like