I need help figuring out what's wrong with my global leaderboard script

I need to figure out what’s wrong with my global leaderboard script. There aren’t any errors, and I’ve debugged it with print()s. It seems to think that there isn’t any data in the Pages table to loop through.

local Leaderboard = game.DataStoreService:GetOrderedDataStore("BasicPlayerData")
local ScrollingFrame = script.Parent

local function UpdateLeaderboard()
	for Number, Slot in ipairs(ScrollingFrame:GetChildren()) do
		if Slot:IsA("Frame") then
			Slot:Destroy()
		end
	end
	local Success, ErrorMessage = pcall (function()
		local Data = Leaderboard:GetSortedAsync(false, 10)
		local Page = Data:GetCurrentPage()
		for Rank, Data in ipairs(Page) do
			local Username = game.Players:GetNameFromUserIdAsync(Data.key)
			local ProfilePicture = game.Players:GetUserThumbnailAsync(Data.key, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size150x150)
			local Template = script.Slot:Clone()
			Template.PlayerName.Text = Username
			Template.ProfilePicture.Image = ProfilePicture
			Template.Parent = ScrollingFrame
		end
	end)
	if not Success then
		print(ErrorMessage)
	end
end

while true do
	UpdateLeaderboard()
	wait(10)
end

My logical first question (since I can’t spot anything immediately wrong with the code) is, do you have data saved to display on the leaderboard? Also, are you sure you are using the correct datastore name?

Yes for both questions. But if ordered datastores are different from normal datastores, then that’s the problem. Is this the case? Do I have to save data to the datastore and the ordered datastore? I thought GetOrderedDataStore() is simply a function to get ordered data from an existing datastore.

Yes, OrderedDataStores and DataStores are completely separate. You must save data to the OrderedDataStore specifically for it to be accessible.

Keep in mind that you can only store positive integer values in OrderedDataStores.

1 Like