Advertisement
Jackthehunter25

Untitled

Dec 29th, 2020
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. local players = game:GetService("Players")
  2. local dataStoreService = game:GetService("DataStoreService")
  3.  
  4. local globalDataStore = dataStoreService:GetOrderedDataStore("CoinsGloball")
  5. local board = game.Workspace.GlobalBoard
  6.  
  7. local template = board.Main.SurfaceGui.Leaderboard.Template:Clone()
  8. board.Main.SurfaceGui.Leaderboard.Template:Destroy()
  9.  
  10. local function update()
  11.  
  12. for _,child in pairs(board.Main.SurfaceGui.Leaderboard:GetChildren()) do
  13.  
  14. if child:IsA("Frame") then
  15.  
  16. child:Destroy()
  17.  
  18.  
  19. end
  20.  
  21. end
  22.  
  23. local success,err = pcall (function()
  24.  
  25. local data = globalDataStore:GetSortedAsync(false,20)
  26. local page = data:GetCurrentPage()
  27.  
  28. for rank,plrData in ipairs(page) do
  29.  
  30. local userid = plrData.key
  31. local coins = plrData.value
  32.  
  33. if rank < 3 then
  34. local npc = workspace:FindFirstAncestor(rank)
  35.  
  36. if npc then
  37.  
  38. npc.UserId.Value = userid
  39. end
  40. end
  41.  
  42.  
  43. local new = template:Clone()
  44. new.PlrName.Text = players:GetNameFromUserIdAsync(userid)
  45. new.PlrAmount.Text = coins
  46. new.LayoutOrder = rank
  47.  
  48. new.Parent = board.Main.SurfaceGui.Leaderboard
  49.  
  50.  
  51. end
  52. end)
  53.  
  54. end
  55.  
  56. while true do
  57.  
  58. update()
  59.  
  60. wait(math.random(2,5))
  61.  
  62. spawn (function()
  63.  
  64. for _,plr in pairs(game.Players:GetPlayers()) do
  65.  
  66. globalDataStore:SetAsync(plr.UserId,plr.leaderstats.Coins.Value)
  67. wait()
  68.  
  69.  
  70. end
  71. end)
  72.  
  73. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement