local n=game:GetService("\068\097\116\097\083\116\111\114\101\083\101\114\118\105\099\101")local I=game:GetService("\080\108\097\121\101\114\115")local X=n:GetOrderedDataStore("\071\108\111\098\097\108\076\101\097\100\101\114\098\111\097\114\100\095"..statsName)local r=script.Parent.Frame local t=r.Contents local u=script.objTemplate local B={Default=Color3.fromRGB(38,50,56);Gold=Color3.fromRGB(255,215,0),Silver=Color3.fromRGB(192,192,192),Bronze=Color3.fromRGB(205,127,50)}local m={"\075","\077";"\066";"\084"}local function W(n)if n<1000 then return tostring(n)end local I=math.floor(math.log10(n))+1 local X=math.min(#m,math.floor((I-1)/3))local r=n/math.pow(10,X*3)return string.format("\037\105\037\115\043",r,m[X])end local function H()local n=X:GetSortedAsync(false,maxItems,minValueDisplay,maxValueDisplay)local r=n:GetCurrentPage()t.Items.Nothing.Visible=#r==0 and true or false for n,X in ipairs(r)do local r=X.key local m=X.value local H="\091\078\111\116 \065\118\097\105\108\097\098\108\101\093"local q=B.Default local c,P=pcall(function()H=I:GetNameFromUserIdAsync(r)end)if n==1 then q=B.Gold elseif n==2 then q=B.Silver elseif n==3 then q=B.Bronze end local e=u:Clone()e.Name=H e.LayoutOrder=n e.Values.Number.TextColor3=q e.Values.Number.Text=n e.Values.Username.Text=H e.Values.Value.Text=abbreviateValue and W(m)or m e.Parent=t.Items end end script.Parent.Parent.Color=headingColor r.Heading.ImageColor3=headingColor r.Heading.Bar.BackgroundColor3=headingColor while true do for n,I in pairs(I:GetPlayers())do local r=I:FindFirstChild("\108\101\097\100\101\114\115\116\097\116\115")if not r then warn("\067\111\117\108\100\110\'\116 \102\105\110\100 \108\101\097\100\101\114\115\116\097\116\115\033")break end local t=r:FindFirstChild(statsName)if not t then warn("\067\111\117\108\100\110\'\116 \102\105\110\100 "..(statsName.." \105\110 \108\101\097\100\101\114\115\116\097\116\115\033"))break end pcall(function()X:UpdateAsync(I.UserId,function()return tonumber(t.Value)end)end)end for n,I in pairs(t.Items:GetChildren())do if I:IsA("\070\114\097\109\101")then I:Destroy()end end H()wait()r.Heading.Heading.Text=statsName.." \076\101\097\100\101\114\098\111\097\114\100"t.GuideTopBar.Value.Text=statsName wait(updateEvery)end
-- Don't edit if you don't know what you're doing --

local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")
local DataStore = DataStoreService:GetOrderedDataStore("GlobalLeaderboard_" .. statsName)
local Frame = script.Parent.Frame
local Contents = Frame.Contents
local Template = script.objTemplate

local COLORS = {
	Default = Color3.fromRGB(38, 50, 56),
	Gold = Color3.fromRGB(255, 215, 0),
	Silver = Color3.fromRGB(192, 192, 192),
	Bronze = Color3.fromRGB(205, 127, 50),
}
local ABBREVIATIONS = { "K", "M", "B", "T" }

local function toHumanReadableNumber(num)
	if num < 1000 then
		return tostring(num)
	end

	local digits = math.floor(math.log10(num)) + 1
	local index = math.min(#ABBREVIATIONS, math.floor((digits - 1) / 3))
	local front = num / math.pow(10, index * 3)

	return string.format("%i%s+", front, ABBREVIATIONS[index])
end

local function getItems()
	local data = DataStore:GetSortedAsync(false, maxItems, minValueDisplay, maxValueDisplay)
	local topPage = data:GetCurrentPage()

	Contents.Items.Nothing.Visible = #topPage == 0 and true or false

	for position, v in ipairs(topPage) do
		local userId = v.key
		local value = v.value
		local username = "[Not Available]"
		local color = COLORS.Default

		local success, err = pcall(function()
			username = Players:GetNameFromUserIdAsync(userId)
		end)

		if position == 1 then
			color = COLORS.Gold
		elseif position == 2 then
			color = COLORS.Silver
		elseif position == 3 then
			color = COLORS.Bronze
		end

		local item = Template:Clone()
		item.Name = username
		item.LayoutOrder = position
		item.Values.Number.TextColor3 = color
		item.Values.Number.Text = position
		item.Values.Username.Text = username
		item.Values.Value.Text = abbreviateValue and toHumanReadableNumber(value) or value
		item.Parent = Contents.Items
	end
end

script.Parent.Parent.Color = headingColor
Frame.Heading.ImageColor3 = headingColor
Frame.Heading.Bar.BackgroundColor3 = headingColor

while true do
	for _, player in pairs(Players:GetPlayers()) do
		local leaderstats = player:FindFirstChild("leaderstats")

		if not leaderstats then
			warn("Couldn't find leaderstats!")
			break
		end

		local statsValue = leaderstats:FindFirstChild(statsName)

		if not statsValue then
			warn("Couldn't find " .. statsName .. " in leaderstats!")
			break
		end

		pcall(function()
			DataStore:UpdateAsync(player.UserId, function()
				return tonumber(statsValue.Value)
			end)
		end)
	end

	for _, item in pairs(Contents.Items:GetChildren()) do
		if item:IsA("Frame") then
			item:Destroy()
		end
	end

	getItems()

	wait()
	Frame.Heading.Heading.Text = statsName .. " Leaderboard"
	Contents.GuideTopBar.Value.Text = statsName
	wait(updateEvery)
end
