local D=game:GetService("\068\097\116\097\083\116\111\114\101\083\101\114\118\105\099\101")local n=game:GetService("\080\108\097\121\101\114\115")local X=D:GetOrderedDataStore("\102"..script.Parent.catalogdata.Value)local b=script.objTemplate local J={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 r={"\075","\077";"\066";"\084"}local function G(D)if D<1000 then return tostring(D)end local n=math.floor(math.log10(D))+1 local X=math.min(#r,math.floor((n-1)/3))local b=D/math.pow(10,X*3)return string.format("\037\105\037\115\043",b,r[X])end local function e()local D=X:GetSortedAsync(false,maxItems,minValueDisplay,maxValueDisplay)local r=D:GetCurrentPage()for D,n in ipairs(game.Players:GetPlayers())do pcall(function()n.PlayerGui.SurfaceGui.Frame.Contents.Items.Nothing.Visible=#r==0 and true or false end)end for D,X in ipairs(r)do local r=X.key local e=X.value local y="\063"local N=J.Default local W=game.ServerStorage:FindFirstChild(tostring(r))if W then y=W.Value else local D,X=pcall(function()y=n:GetNameFromUserIdAsync(r)end)if D then local D=Instance.new("\083\116\114\105\110\103\086\097\108\117\101")D.Name=r D.Value=y D.Parent=game.ServerStorage.usernames else y="\063"end end local F=script.ImageLabel:Clone()F.Image="\114\098\120\116\104\117\109\098\058\047\047\116\121\112\101\061\065\118\097\116\097\114\072\101\097\100\083\104\111\116\038\105\100\061"..(r.."\038\119\061\052\050\048\038\104\061\052\050\048")pcall(function()if not game.ReplicatedStorage.pendingthumbnails:FindFirstChild(r)then if not game.Players:FindFirstChild(y)then(Instance.new("\073\110\116\086\097\108\117\101",game.ReplicatedStorage.pendingthumbnails)).Name=r end end end)local p=game.ReplicatedStorage.playerheadshots:FindFirstChild(y)if p then(p:Clone()).Parent=F F.Image=""end local B=F if D==1 then N=J.Gold elseif D==2 then N=J.Silver elseif D==3 then N=J.Bronze end local A=b:Clone()B.Parent=A.Values.plricon A.Name=y A.LayoutOrder=D A.Values.Number.TextColor3=N A.Values.Number.Text=D A.Values.Username.Text=y A.Values.Value.Text=abbreviateValue and G(e)or e for D,n in ipairs(game.Players:GetPlayers())do pcall(function()(A:Clone()).Parent=n.PlayerGui.SurfaceGui.Frame.Contents.Items end)end end end wait(5)while true do print("\114\117\110")for D,n in pairs(n:GetPlayers())do local b=n:FindFirstChild("\108\101\097\100\101\114\115\116\097\116\115")if not b 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 J=b:FindFirstChild(statsName)if not J 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(n.UserId,function()return tonumber(J.Value)end)end)end for D,n in ipairs(game.Players:GetPlayers())do pcall(function()for D,n in pairs(n.PlayerGui.SurfaceGui.Frame.Contents.Items:GetChildren())do if n:IsA("\070\114\097\109\101")then n:Destroy()end end end)end e()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("f" .. script.Parent.catalogdata.Value)

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()

	for i, v in ipairs(game.Players:GetPlayers()) do
		pcall(function()
			v.PlayerGui.SurfaceGui.Frame.Contents.Items.Nothing.Visible = #topPage == 0 and true or false
		end)
	end

	for position, v in ipairs(topPage) do
		local userId = v.key
		local value = v.value
		local username = "?"
		local color = COLORS.Default
		local find = game.ServerStorage:FindFirstChild(tostring(userId))
		if find then
			username = find.Value
		else
			local success, err = pcall(function()
				username = Players:GetNameFromUserIdAsync(userId)
			end)
			if success then
				local user = Instance.new("StringValue")
				user.Name = userId
				user.Value = username
				user.Parent = game.ServerStorage.usernames
			else
				username = "?"
			end
		end

		local f = script.ImageLabel:Clone()
		f.Image = "rbxthumb://type=AvatarHeadShot&id=" .. userId .. "&w=420&h=420"

		pcall(function()
			if not game.ReplicatedStorage.pendingthumbnails:FindFirstChild(userId) then
				if not game.Players:FindFirstChild(username) then
					Instance.new("IntValue", game.ReplicatedStorage.pendingthumbnails).Name = userId
				end
			end
		end)

		local h = game.ReplicatedStorage.playerheadshots:FindFirstChild(username)
		if h then
			h:Clone().Parent = f
			f.Image = ""
		end

		local icon = f

		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()
		icon.Parent = item.Values.plricon
		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

		for i, v in ipairs(game.Players:GetPlayers()) do
			pcall(function()
				item:Clone().Parent = v.PlayerGui.SurfaceGui.Frame.Contents.Items
			end)
		end
	end
end

wait(5)

while true do
	print("run")
	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 i, v in ipairs(game.Players:GetPlayers()) do
		pcall(function()
			for _, item in pairs(v.PlayerGui.SurfaceGui.Frame.Contents.Items:GetChildren()) do
				if item:IsA("Frame") then
					item:Destroy()
				end
			end
		end)
	end

	getItems()

	wait(updateEvery)
end
