function Scale()local J=GrabMagnitude()if not J or lastMagnitude and math.abs(lastMagnitude-J)<differenceToScan or lastMagnitude and(lastMagnitude>=bestResolution and J>=bestResolution)then return end lastMagnitude=J local p=maxDownscale+(math.min(J,bestResolution)/bestResolution)*(1-maxDownscale)for J,A in ipairs((_L.Player.Get("\080\108\097\121\101\114\071\117\105")):GetChildren())do if A.ClassName=="\083\099\114\101\101\110\071\117\105"and not _L.Functions.SearchArray(blacklist,A.Name)then for J,A in ipairs(A:GetDescendants())do if J%200==0 then wait()end if(A.ClassName=="\073\109\097\103\101\076\097\098\101\108"or A.ClassName=="\073\109\097\103\101\066\117\116\116\111\110")and A.ScaleType==Enum.ScaleType.Slice then if not archive[A]then archive[A]=A.SliceScale end local J=archive[A]A.SliceScale=J*p end end end end end function GrabMagnitude()local J=(_L.Player.Get("\067\097\109\101\114\097")).ViewportSize if J then local p=J.Magnitude return p end end



function Scale()
	local magnitude = GrabMagnitude()
	
	--- Don't run this if we don't need to (resolution hasn't changed much)
	if (not magnitude) or (lastMagnitude and math.abs(lastMagnitude - magnitude) < differenceToScan) or (lastMagnitude and lastMagnitude >= bestResolution and magnitude >= bestResolution) then
		return
	end
	lastMagnitude = magnitude
	
	--- Calculate ratio
	local ratio = maxDownscale + ((math.min(magnitude, bestResolution) / bestResolution) * (1 - maxDownscale))
	
	
	--- Change 9Slices
	for _, gui in ipairs(_L.Player.Get("PlayerGui"):GetChildren()) do
		if gui.ClassName == "ScreenGui" and (not _L.Functions.SearchArray(blacklist, gui.Name)) then
			for i, v in ipairs(gui:GetDescendants()) do
				--- Yield to prevent microstuttering for lots of gui elements
				if i%200 == 0 then
					wait()
				end
				
				--- Adjust 9slice scaling ratio based on resolution
				if (v.ClassName == "ImageLabel" or v.ClassName == "ImageButton") and v.ScaleType == Enum.ScaleType.Slice then
					if not archive[v] then
						archive[v] = v.SliceScale
					end
					local base = archive[v]
					v.SliceScale = base * ratio
				end
			end
		end
	end
end


function GrabMagnitude()
	local resolution = _L.Player.Get("Camera").ViewportSize
	if resolution then
		local magnitude = resolution.Magnitude
		return magnitude
	end
end

