How many scales to make it equal to 1 offset position?

So…,when I want to make a Frame/Text Label…etc fit all platforms
I’m going to change their position to scale and adjust their anchorpoint and as you know it will move them somewhere else and take a while. So I tried to make a plugin that can fit a gui one way. automatically without making it move unwanted.

And yes, it works great as I expected! No even very small position change while the anchorpoint has changed.

But as the title says…I want to add a feature that automatically converts offsets to scale, but I don’t know where to start?

Core This Plugin

local toolbar = plugin:CreateToolbar("Gui Tools :O")
local Selection = game:GetService("Selection")

local ButtonPos = toolbar:CreateButton("Fit pos gui", "Fit gui with scale and anchor", "rbxassetid://4458901886")

ButtonPos.Click:Connect(function()
	local IsSaved = false
	local function SaveHistory(Name:string)
		if IsSaved == false then
			local M = game:GetService("ChangeHistoryService"):SetWaypoint(Name) or game:GetService("ChangeHistoryService"):SetWaypoint('')
			IsSaved = true
		end
	end
	
	
	if Selection:Get()[1] ~= nil then
		local function Fit(v:Frame)
			IsSaved = false
			local i:Frame 
			--Im not good english so im need this to get properties (like i.si = i.Size = v.Size) :)
			local OldAbsoPos = v.AbsolutePosition
			v.AnchorPoint = Vector2.new(0.5,1)
			
			
			if v.AbsolutePosition ~= OldAbsoPos then --Just little checking 
				
				local SizeX
				local SizeY
				do --Get player's size screen thought the Roblox's fit gui
					local Old = v.Size
					v.Size = UDim2.new(1,0,1,0)
					SizeX = v.AbsoluteSize.X
					SizeY = v.AbsoluteSize.Y
					v.Size = Old
				end
				
				local FitX = v.AnchorPoint.X --(0,5) / ScreenX
				local FitY = v.AnchorPoint.Y --(1) / ScreenY
				
			
				
				
				print(SizeX,SizeY)
				
				--Take Current X Pos To Old
				v.Position = UDim2.new(v.Position.X.Scale+((FitX/SizeX)*v.AbsoluteSize.X),0,v.Position.Y.Scale,0)
				--Y
				v.Position = UDim2.new(v.Position.X.Scale,0,v.Position.Y.Scale+((FitY/SizeY)*v.AbsoluteSize.Y),0)
				
				
				
			end
			task.wait()
			SaveHistory('Fit '..v:GetFullName())
			print('kkk!')
		end
		

		for i,v in pairs(Selection:Get()) do --Fit all gui player's selecting!
			pcall(function()
				if v.Position then
					Fit(v)
				end
			end)
		end
		
		SaveHistory("Last fit click!")
	else
		warn('You Need Seclect Something To Fit!')
	end

end)
1 Like
local oneOffsetToXScale = 1 / Camera.ViewportSize.X
local oneOffsetToYScale = 1 / Camera.ViewportSize.Y
1 Like

Oh,Thanks you sir it’s works! :open_mouth:

1 Like