Z_Dev

global boi

Feb 7th, 2021
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.01 KB | None | 0 0
  1. local StatsName = "Wins"
  2. local MaxItems = 100
  3. local MinValueDisplay = 1
  4. local MaxValueDisplay = 10e15
  5. local UpdateEvery = 60
  6.  
  7. local DataStoreService = game:GetService("DataStoreService")
  8. local DataStore = DataStoreService:GetOrderedDataStore("GlobalLeaderboard_" .. StatsName)
  9. local SurfaceGui = script.Parent
  10. local Sample = script.Sample
  11. local List = SurfaceGui.Frame.List
  12. local ItemsFrame = List.ListContent.Items
  13.  
  14. local function GetItems()
  15.     local Data = DataStore:GetSortedAsync(false, MaxItems, MinValueDisplay, MaxValueDisplay)
  16.     local TopPage = Data:GetCurrentPage()
  17.    
  18.     ItemsFrame.Nothing.Visible = #TopPage == 0 and true or false
  19.    
  20.     for i, v in ipairs(TopPage) do
  21.         local UserId = v.key
  22.         local Value = v.value
  23.         local Username = "[Not Available]"
  24.         local Color = Color3.fromRGB(38, 50, 56)
  25.        
  26.         local Success, Error = pcall(function()
  27.             Username = game.Players:GetNameFromUserIdAsync(UserId)
  28.         end)
  29.        
  30.         if i == 1 then
  31.             Color = Color3.fromRGB(255, 215, 0)
  32.         elseif i == 2 then
  33.             Color = Color3.fromRGB(192, 192, 192)
  34.         elseif i == 3 then
  35.             Color = Color3.fromRGB(205, 127, 50)
  36.         end
  37.        
  38.         local Item = Sample:Clone()
  39.         Item.Name = Username
  40.         Item.LayoutOrder = i
  41.         Item.Values.Number.TextColor3 = Color
  42.         Item.Values.Number.Text = i
  43.         Item.Values.Username.Text = Username
  44.         Item.Values.Value.Text = Value
  45.         Item.Parent = ItemsFrame
  46.     end
  47. end
  48.  
  49. while true do
  50.     for i, v in pairs(game.Players:GetPlayers()) do
  51.         local Stats = v.leaderstats:WaitForChild(StatsName).Value
  52.         if Stats then
  53.             pcall(function()
  54.                 DataStore:UpdateAsync(v.UserId, function(Value)
  55.                     return tonumber(Stats)
  56.                 end)
  57.             end)
  58.         end
  59.     end
  60.    
  61.     for i, v in pairs(ItemsFrame:GetChildren()) do
  62.         if v:IsA("ImageLabel") then
  63.             v:Destroy()
  64.         end
  65.     end
  66.    
  67.     GetItems()
  68.    
  69.     wait()
  70.     SurfaceGui.Heading.Heading.Text = StatsName .. " Leaderboard"
  71.     List.ListContent.GuideTopBar.Value.Text = StatsName
  72.     List.CanvasSize = UDim2.new(0, 0, 0, ItemsFrame.UIListLayout.AbsoluteContentSize.Y + 35)
  73.     wait(UpdateEvery)
  74. end
Advertisement
Add Comment
Please, Sign In to add comment