Hello! I am attempting to make a leaderboard in my game that will show the top donators in my game. When I attempt to test it, I get no errors, but also nothing happens with the leaderboard. So the script is basically doing nothing??? Any ideas are appreciated. Here is my code:
local ds = game:GetService("DataStoreService"):GetOrderedDataStore("Donations")
while true do
for _, m in pairs(script.Parent:GetChildren()) do
if m:IsA("ImageLabel") then m:Destroy() end
end
local s, r = pcall(function()
local data = ds:GetSortedAsync(false, 5)
local donationsPage = data:GetCurrentPage()
for rank, value in ipairs(donationsPage) do
if rank <= 50 then
local name = game:GetService("Players"):GetNameFromUserIdAsync(tonumber(value.key))
local donationAmount = value.value
local template = script:WaitForChild("Template"):Clone()
template.Name = rank .. "_" .. donationAmount
template:WaitForChild("Rank").Text = rank
template:WaitForChild("Username").Text = name
template:WaitForChild("Donated").Text = donationAmount
template.Parent = script.Parent
template.Visible = true
end
end
end)
if not s then warn(r) end
wait(300)
end
UPDATE: I have put a print inside the code and realised that the ipairs loop is not running at all. This is likely my problem, however this data should not be empty.
I am not super intelligent. I am so sorry for being so idiotic, but it turns out Ordered data stores and Data stores are completely seperate, so I have converted my game to ordered data stores and now it works fine. Thank you to everyone to helped me out.