dogo8me

OrderedDataStore infinite display

Jul 12th, 2024
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.68 KB | Source Code | 0 0
  1. -- Pushes the limit of the ordered datastore from 100, to infinite
  2. local DataStoreService = game:GetService("DataStoreService")
  3. local scrollingFrame = workspace.Part.SurfaceGui.ScrollingFrame
  4. local HttpService = game:GetService("HttpService")
  5. local DataStore = DataStoreService:GetOrderedDataStore("OrderedDataStore1")
  6. local tableSize = 100
  7.  
  8. local overallRank = 0
  9. local pages = DataStore:GetSortedAsync(false, tableSize)
  10.  
  11. scrollingFrame.DescendantAdded:Connect(function()
  12.     local childrenCount = -1
  13.     for i,v in scrollingFrame:GetChildren() do
  14.         childrenCount += 1
  15.     end
  16.     local devidedNumber = math.ceil(childrenCount / 10)
  17.     scrollingFrame.CanvasSize = UDim2.new(0,0,devidedNumber,0)
  18. end)
  19.  
  20. -- Update leaderboard
  21. while true do    
  22.     print("Refreshed")
  23.     -- Get the datastore data
  24.     local entries = pages:GetCurrentPage()
  25.    
  26.  
  27.     local indexTable = {}
  28.     -- Get the sorted data from the current page and display it
  29.     for rank, entry in ipairs(entries) do
  30.         overallRank += 1
  31.         local template = game.ReplicatedStorage.Template:Clone()
  32.         template.Parent = scrollingFrame
  33.         template.Statistic.Text = tostring(entry.value)
  34.         template.Username.Text = entry.key
  35.         template.Rank.Text = tostring(overallRank)
  36.         local index = math.floor((overallRank - 1) / tableSize)
  37.         indexTable[entry.key] = {playerRank = overallRank, index = index}
  38.     end
  39.  
  40.     -- Check if all pages are finished processing
  41.     if pages.IsFinished then
  42.         task.wait(5)
  43.         overallRank = 0
  44.         pages = DataStore:GetSortedAsync(false,tableSize)
  45.         for i,guiObject in scrollingFrame:GetChildren() do
  46.             wait(0.1)
  47.             if not guiObject:IsA("UIListLayout") then
  48.                 guiObject:Remove()
  49.             end
  50.         end
  51.     else
  52.         pages:AdvanceToNextPageAsync()
  53.     end
  54. end
Advertisement
Add Comment
Please, Sign In to add comment