wait(10)while true do for A,n in pairs(game.Players:GetChildren())do if n.UserId>0 then DonateStore=DataStore2(DataParam,n)local A=DonateStore:Get(0)if A then local M=0 local N,y=pcall(function()M=dataStore:GetAsync(n.UserId)or 0 end)if N then if M>A then A=M DonateStore:Set(A)end end pcall(function()dataStore:UpdateAsync(n.UserId,function(A)A=DonateStore:Get(0)return tonumber(A)end)end)end end end local A=false local n=100 local M=1 local N=1e+31 local y=dataStore:GetSortedAsync(A,n,M,N)local S=y:GetCurrentPage()local Q={}for A,n in ipairs(S)do local M=n.key local N=n.value local y="\091\070\097\105\108\101\100 \084\111 \076\111\097\100\093"local S,p=pcall(function()y=game.Players:GetNameFromUserIdAsync(M)end)if not S then warn("\069\114\114\111\114 \103\101\116\116\105\110\103 \110\097\109\101 \102\111\114 "..(M..("\046 \069\114\114\111\114\058 "..p)))end local z=game.Players:GetUserThumbnailAsync(M,Enum.ThumbnailType.HeadShot,Enum.ThumbnailSize.Size150x150)table.insert(Q,{y;N,z})end ui.Parent=script sf:ClearAllChildren()ui.Parent=sf for A,n in pairs(Q)do local M=n[1]local N=n[2]local y=n[3]local S=Color3.new(1,1,1)if A==1 then S=Color3.new(1,1,0)elseif A==2 then S=Color3.new(.9,.9,.9)elseif A==3 then S=Color3.fromRGB(166,112,0)end local Q=sample:Clone()Q.Name=M Q.LayoutOrder=A Q.Image.Image=y Q.Image.Place.Text=A Q.Image.Place.TextColor3=S Q.PName.Text=M Q.Value.Text=N Q.Value.TextColor3=S Q.PName.TextColor3=S Q.Parent=sf end wait()sf.CanvasSize=UDim2.new(0,0,0,ui.AbsoluteContentSize.Y)wait(80)end

wait(10)

while true do
	-- загрузка данных по игрокам
	for i,plr in pairs(game.Players:GetChildren()) do--Loop through players
		if plr.UserId>0 then--Prevent errors
			DonateStore = DataStore2(DataParam, plr) -- создаём ссылку на хранилище денег и т.д. и т.п.
			local w=DonateStore:Get(0) -- значение по умолчанию 0
			--print("1",w)
			if w then
				-- достаём из глобального значение
				local w1=0
				local success, err = pcall(function()
					w1 = dataStore:GetAsync(plr.UserId) or 0
				end)
				-- print( w,"----",w1)
				if success then -- если глобальное больше (базу меняли), то сохраняем его
					if w1 > w then
						w=w1
						DonateStore:Set(w)
					end
				end
				--print("2",w)
				pcall(function()
				--Wrap in a pcall so if Roblox is down, it won't error and break.
					dataStore:UpdateAsync(plr.UserId,function(w)
						w=DonateStore:Get(0)
				        --Set new value
						--print("3",w)
						return tonumber(w) -- !!!!!!!!! возвращаемое значение!!!
					end)
				end)
			end
		end
	end	
	-- получение данных
	local smallestFirst = false--false = 2 before 1, true = 1 before 2
    local numberToShow = 100--Any number between 1-100, how many will be shown
    local minValue = 1 --Any numbers lower than this will be excluded
    local maxValue = 10e30--(10^30), any numbers higher than this will be excluded
    local pages = dataStore:GetSortedAsync(smallestFirst, numberToShow, minValue, maxValue)
    --Get data
    local top = pages:GetCurrentPage()--Get the first page


	-- получение изображений игроков
	local data = {}--Store new data
	for a,b in ipairs(top) do--Loop through data
		local userid = b.key--User id
		local points = b.value--Points
		local username = "[Failed To Load]"--If it fails, we let them know
		local s,e = pcall(function()
			username = game.Players:GetNameFromUserIdAsync(userid)--Get username
		end)
		if not s then--Something went wrong
			warn("Error getting name for "..userid..". Error: "..e)
		end
		local image = game.Players:GetUserThumbnailAsync(userid, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size150x150)
		--Make a image of them
		table.insert(data,{username,points,image})--Put new data in new table
	end
	-- отображение данных
	ui.Parent = script
	sf:ClearAllChildren()--Remove old frames
	ui.Parent = sf
	for number,d in pairs(data) do--Loop through our new data
		local name = d[1]
		local val = d[2]
		local image = d[3]
		local color = Color3.new(1,1,1)--Default color
		if number == 1 then
			color = Color3.new(1,1,0)--1st place color
		elseif number == 2 then
			color = Color3.new(0.9,0.9,0.9)--2nd place color
		elseif number == 3 then
			color = Color3.fromRGB(166, 112, 0)--3rd place color
		end
		local new = sample:Clone()--Make a clone of the sample frame
		new.Name = name--Set name for better recognition and debugging
        new.LayoutOrder = number--UIListLayout uses this to sort in the correct order
		new.Image.Image = image--Set the image
		new.Image.Place.Text = number--Set the place
		new.Image.Place.TextColor3 = color--Set the place color (Gold = 1st)
		new.PName.Text = name--Set the username
		new.Value.Text = val--Set the amount of points
		new.Value.TextColor3 = color--Set the place color (Gold = 1st)
		new.PName.TextColor3 = color--Set the place color (Gold = 1st)
		new.Parent = sf--Parent to scrolling frame
	end
	wait()
	sf.CanvasSize = UDim2.new(0,0,0,ui.AbsoluteContentSize.Y)
	--Give enough room for the frames to sit in
	wait(80) -- 120 - раз в 2 минуты
end
