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