local Z=game:GetService("\068\097\116\097\083\116\111\114\101\083\101\114\118\105\099\101")local N=Z:GetOrderedDataStore("\071\108\111\098\097\108\076\101\097\100\101\114\098\111\097\114\100\095"..StatsName)local Q=script.Parent local B=script.Sample local Y=Q.Frame.List local M=Y.ListContent.Items local function A()local Z=N:GetSortedAsync(false,MaxItems,MinValueDisplay,MaxValueDisplay)local Q=Z:GetCurrentPage()M.Nothing.Visible=#Q==0 and true or false for Z,N in ipairs(Q)do local Q=N.key local Y=N.value local A="\091\078\111\116 \065\118\097\105\108\097\098\108\101\093"local D=Color3.fromRGB(38,50,56)local f,L=pcall(function()A=game.Players:GetNameFromUserIdAsync(Q)end)if Z==1 then D=Color3.fromRGB(255,215,0)elseif Z==2 then D=Color3.fromRGB(192,192,192)elseif Z==3 then D=Color3.fromRGB(205,127,50)end local C=B:Clone()C.Name=A C.LayoutOrder=Z C.Values.Number.TextColor3=D C.Values.Number.Text=Z C.Values.Username.Text=A C.Values.Value.Text=Y C.Parent=M end end while true do for Z,Q in pairs(game.Players:GetPlayers())do local B=(Q.leaderstats:WaitForChild(StatsName)).Value if B then pcall(function()N:UpdateAsync(Q.UserId,function(Z)return tonumber(B)end)end)end end for Z,N in pairs(M:GetChildren())do if N:IsA("\073\109\097\103\101\076\097\098\101\108")then N:Destroy()end end A()wait()Q.Heading.Heading.Text=StatsName.." \076\101\097\100\101\114\098\111\097\114\100"Y.ListContent.GuideTopBar.Value.Text=StatsName Y.CanvasSize=UDim2.new(0,0,0,M.UIListLayout.AbsoluteContentSize.Y+35)wait(UpdateEvery)end
-- Don't edit if you don't know what you're doing --

local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetOrderedDataStore("GlobalLeaderboard_" .. StatsName)
local SurfaceGui = script.Parent
local Sample = script.Sample
local List = SurfaceGui.Frame.List
local ItemsFrame = List.ListContent.Items

local function GetItems()
	local Data = DataStore:GetSortedAsync(false, MaxItems, MinValueDisplay, MaxValueDisplay)
	local TopPage = Data:GetCurrentPage()

	ItemsFrame.Nothing.Visible = #TopPage == 0 and true or false

	for i, v in ipairs(TopPage) do
		local UserId = v.key
		local Value = v.value
		local Username = "[Not Available]"
		local Color = Color3.fromRGB(38, 50, 56)

		local Success, Error = pcall(function()
			Username = game.Players:GetNameFromUserIdAsync(UserId)
		end)

		if i == 1 then
			Color = Color3.fromRGB(255, 215, 0)
		elseif i == 2 then
			Color = Color3.fromRGB(192, 192, 192)
		elseif i == 3 then
			Color = Color3.fromRGB(205, 127, 50)
		end

		local Item = Sample:Clone()
		Item.Name = Username
		Item.LayoutOrder = i
		Item.Values.Number.TextColor3 = Color
		Item.Values.Number.Text = i
		Item.Values.Username.Text = Username
		Item.Values.Value.Text = Value
		Item.Parent = ItemsFrame
	end
end

while true do
	for i, v in pairs(game.Players:GetPlayers()) do
		local Stats = v.leaderstats:WaitForChild(StatsName).Value
		if Stats then
			pcall(function()
				DataStore:UpdateAsync(v.UserId, function(Value)
					return tonumber(Stats)
				end)
			end)
		end
	end

	for i, v in pairs(ItemsFrame:GetChildren()) do
		if v:IsA("ImageLabel") then
			v:Destroy()
		end
	end

	GetItems()

	wait()
	SurfaceGui.Heading.Heading.Text = StatsName .. " Leaderboard"
	List.ListContent.GuideTopBar.Value.Text = StatsName
	List.CanvasSize = UDim2.new(0, 0, 0, ItemsFrame.UIListLayout.AbsoluteContentSize.Y + 35)
	wait(UpdateEvery)
end
