Advertisement
HowToRoblox

GlobalLBHandler

May 3rd, 2020
6,155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.28 KB | None | 0 0
  1. local ds = game:GetService("DataStoreService")
  2.  
  3. local coinsODS = ds:GetOrderedDataStore("CoinsStats")
  4.  
  5.  
  6. local timeUntilReset = 10
  7.  
  8.  
  9. while wait(1) do
  10.    
  11.    
  12.     timeUntilReset = timeUntilReset - 1
  13.    
  14.     script.Parent.Parent.ResetTime.Text = "Resetting in " .. timeUntilReset .. " seconds..."
  15.    
  16.    
  17.     if timeUntilReset == 0 then
  18.        
  19.         timeUntilReset = 10
  20.    
  21.    
  22.         for i, plr in pairs(game.Players:GetPlayers()) do
  23.            
  24.             coinsODS:SetAsync(plr.UserId, plr.leaderstats.Coins.Value)
  25.         end
  26.        
  27.         for i, leaderboardRank in pairs(script.Parent:GetChildren()) do
  28.            
  29.             if leaderboardRank.ClassName == "Frame" then
  30.                 leaderboardRank:Destroy()
  31.             end
  32.         end
  33.        
  34.        
  35.         local success, errorMsg = pcall(function()
  36.            
  37.             local data = coinsODS:GetSortedAsync(false, 5)
  38.             local coinsPage = data:GetCurrentPage()
  39.            
  40.             for rankInLB, dataStored in ipairs(coinsPage) do
  41.                
  42.                
  43.                 local name = game.Players:GetNameFromUserIdAsync(tonumber(dataStored.key))
  44.                 local coins = dataStored.value
  45.                
  46.                
  47.                 local template = script.Template:Clone()
  48.                
  49.                 template.Name = name .. "Leaderboard"
  50.                
  51.                 template.PlrName.Text = name
  52.                
  53.                 template.Rank.Text = "#" .. rankInLB
  54.                
  55.                 template.Coins.Text = coins
  56.                
  57.                 template.Parent = script.Parent            
  58.             end        
  59.         end)
  60.     end
  61. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement