Hello Developer Forum. I have been at this issue for about a week and cannot figure it out. The function AdvanceToNextPageAsync()
has been erroring crazy. I tried wrapping it in pcalls but now it takes forever for leaderboards to even initialize and it seems they wont even update after the first time anymore, I’m just left more confused than ever.
Note: this code runs perfectly fine in studio, but not in public servers, hope that info is helpful.
Code:
local sg = script.Parent
local sample = script:WaitForChild("Sample")
local sf = sg:WaitForChild("ScrollingFrame")
local ui = sf:WaitForChild("UI")
local DataStoreService = game:GetService("DataStoreService")
local DataStoreName = "MainGameData"
local DataStore = DataStoreService:GetDataStore(DataStoreName)
local update = nil
local T = {"K","M","B","T","q","Q","s","S","O","N","d","U","D"}
local function formatNumber(n)
if not tonumber(n) then return n end
if n < 10000 then return math.floor(n) end
local d = math.floor(math.log10(n)/3)*3
local s = tostring(n/(10^d)):sub(1,5)
return s.." "..tostring(T[math.floor(d/3)])
end
local dataStoreService = game:GetService("DataStoreService")
local dataStore = dataStoreService:GetOrderedDataStore("DonationLeaderboard")
wait(5)
update = true
while true do
local Success, Pages = pcall(function()
return DataStore:ListKeysAsync()
end)
if not Success then warn("Timeout") return end
while update do
local Items = Pages:GetCurrentPage()
for _, Data in ipairs(Items) do
local Key = Data.KeyName
local value = DataStore:GetAsync(Key)
local data=value or {}
local sdaroc = data["important"]["Donations"]
if sdaroc then
pcall(function()
dataStore:SetAsync(Key,sdaroc)
end)
end
task.wait()
end
if Pages.IsFinished then
update = false
break end
repeat
local Success, Errormessage = pcall(function()
Pages:AdvanceToNextPageAsync()
end)
if not Success then
task.wait(1)
print("did not advance page dono leaderbaord")
end
until Success
end
local smallestFirst = false
local numberToShow = 100
local minValue = 1
local maxValue = 10e30
local pages = dataStore:GetSortedAsync(smallestFirst, numberToShow, minValue, maxValue)
local top = pages:GetCurrentPage()
local data = {}
for a,b in ipairs(top) do
local userid = b.key
local sadrocks = b.value
local username = "[Failed To Load]"
local s,e = pcall(function()
username = game.Players:GetNameFromUserIdAsync(userid)
end)
if not s then
warn("Error getting name for "..userid..". Error: "..e)
end
local image = game.Players:GetUserThumbnailAsync(userid, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size150x150)
table.insert(data,{username,sadrocks, image})
end
ui.Parent = script
sf:ClearAllChildren()
ui.Parent = sf
for number,d in pairs(data) do
local name = d[1]
local val = d[2]
local image = d[3]
local color = Color3.new(1,1,1)
if number == 1 then
color = Color3.fromRGB(255, 243, 79)
elseif number == 2 then
color = Color3.fromRGB(171, 209, 229)
elseif number == 3 then
color = Color3.fromRGB(255, 159, 103)
end
local new = sample:Clone()
new.Image.Image = image
new.LayoutOrder = number
new.Rank.Text = "#".. number
new.Rank.TextColor3 = color
new.PName.Text = name .. " | "
new.Value.Text = formatNumber(val)
new.Value.TextColor3 = color
new.PName.TextColor3 = color
new.Parent = sf
end
wait()
update = false
wait(120)
end
repeat
local Success, Errormessage = pcall(function()
Pages:AdvanceToNextPageAsync()
end)
if not Success then
task.wait(1)
print(“did not advance page dono leaderboard”)
end
until Success
this is the main portion of code I believe is causing the issues.
EDIT: Tried the method recommended, there are no errors in console anymore but it just prints over and over "“did not advance page dono leaderboard”. Eventually after multiple minutes it will show but then it will never update it no matter how long I wait.