local f=game:GetService("\068\097\116\097\083\116\111\114\101\083\101\114\118\105\099\101")local K=game:GetService("\080\108\097\121\101\114\115")local k=f:GetOrderedDataStore("\070\097\105\108\115")local Z=script.Parent.Frame local n=Z.Contents local x=script.objTemplate local V={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 b={"\075","\077","\066";"\084"}local function w(f)if f<1000 then return tostring(f)end local K=math.floor(math.log10(f))+1 local k=math.min(#b,math.floor((K-1)/3))local Z=f/math.pow(10,k*3)return string.format("\037\105\037\115\043",Z,b[k])end local function o()local f=k:GetSortedAsync(false,maxItems,minValueDisplay,maxValueDisplay)local Z=f:GetCurrentPage()n.Items.Nothing.Visible=#Z==0 and true or false for f,k in ipairs(Z)do local Z=k.key local b=k.value local o="\091\078\111\116 \065\118\097\105\108\097\098\108\101\093"local d=V.Default local j,y=pcall(function()o=K:GetNameFromUserIdAsync(Z)end)if f==1 then d=V.Gold elseif f==2 then d=V.Silver elseif f==3 then d=V.Bronze end local q=x:Clone()q.Name=o q.LayoutOrder=f q.Values.Number.TextColor3=d q.Values.Number.Text=f q.Values.Username.Text=o q.Values.Value.Text=abbreviateValue and w(b)or b q.Parent=n.Items end end script.Parent.Parent.Color=headingColor Z.Heading.ImageColor3=headingColor Z.Heading.Bar.BackgroundColor3=headingColor while true do for f,K in pairs(K:GetPlayers())do local Z=K:FindFirstChild("\108\101\097\100\101\114\115\116\097\116\115")if not Z 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 n=Z:FindFirstChild(statsName)if not n 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()k:UpdateAsync(K.UserId,function()return tonumber(n.Value)end)end)end for f,K in pairs(n.Items:GetChildren())do if K:IsA("\070\114\097\109\101")then K:Destroy()end end o()wait()Z.Heading.Heading.Text=statsName.." \076\101\097\100\101\114\098\111\097\114\100"n.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("Fails")
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
