I want to know how to get the top player in the global leaderboard so I can give them a reward!
Script
local Abbreviations = {'','K','M','B','T','qd','Qn','sx','Sp','O','N','de','Ud','DD','tdD','qdD','QnD','sxD','SpD','OcD','NvD','Vgn','UVg','DVg','TVg','qtV','QnV','SeV','SPG','OVG','NVG','TGN','UTG','DTG','tsTG','qtTG','QnTG','ssTG','SpTG','OcTG','NoAG','UnAG','DuAG','TeAG','QdAG','QnAG','SxAG','SpAG','OcAG','NvAG','CT'}
local function Format(Value)
for i = 1, #Abbreviations do
if tonumber(Value) < 10^(i*3) then
return math.floor(Value/((10^((i-1)*3))/100))/(100) .. Abbreviations[i]
end
end
end
local DataStore1 = game:GetService("DataStoreService"):GetOrderedDataStore("ReleaseBoard1")
while true do
for _,Player in pairs(game.Players:GetPlayers()) do
local Leaderstats = Player:FindFirstChild("Leaderstats")
if Leaderstats then
local Cash = Leaderstats.CoinsBoard
if Cash then
DataStore1:SetAsync(Player.UserId, Cash.Value)
end
end
end
local Leaderboards = game.Workspace:WaitForChild("Leaderboards")
local Selected = Leaderboards:WaitForChild("CashHolder")
local Count = Leaderboards:WaitForChild("CashCounter")
local Info = Count:WaitForChild("BillboardGui")
for i,v in pairs(Selected.SurfaceGui:WaitForChild("ScrollingFrame"):GetChildren()) do
v:Destroy()
end
for i,v in pairs(game.Workspace.Leaderboards.TopCash:GetChildren()) do
v:Destroy()
end
local Success,Error = pcall(function()
local Data = DataStore1:GetSortedAsync(false, 50)
local Page = Data:GetCurrentPage()
for i,v in pairs(Page) do
if v.key ~= nil and tonumber(v.key) and tonumber(v.key) > 0 then
local Name = game:GetService("Players"):GetNameFromUserIdAsync(v.key)
if Name ~= nil then
local Value = v.value
local New = game.ServerStorage:WaitForChild("CashTemplate"):Clone()
New:WaitForChild("PlayerIcon").Image = "https://www.roblox.com/headshot-thumbnail/image?userId="..(v.key).."&width=150&height=150&format=png"
New:WaitForChild("Currency").Text = Format(Value)
New:WaitForChild("PlaceValue").Text = "#" .. i
New:WaitForChild("PlayerName").Text = Name
local Leaderboards = game.Workspace:WaitForChild("Leaderboards")
local Selected = Leaderboards:WaitForChild("CashHolder")
New.Position = UDim2.new(0, 0, New.Position.Y.Scale + (0.02 * #Selected.SurfaceGui:WaitForChild("ScrollingFrame"):GetChildren()), 0)
New.Parent = Selected.SurfaceGui:WaitForChild("ScrollingFrame")
end
end
end
end)
if not Success then
error(Error)
end
for i = 30,1,-1 do
wait(1)
Info:WaitForChild("TextLabel").Text = "Updates In: [" .. i .. "]"
end
wait()
end