Why is this scaling incorrectly?

Any ideas why this is happening?

Btw, I am used aspect ratio constraint.

		local xPos = Mouse.X
		local yPos = Mouse.Y

		local paintCloned = paint:Clone()

		local offset = Vector2.new(math.abs(xPos - canvas.AbsolutePosition.X), math.abs(yPos - canvas.AbsolutePosition.Y))

		paintCloned.Size = UDim2.new(0, size, 0, size)
		paintCloned.Position = UDim2.new(0, offset.X, 0, offset.Y)
		paintCloned.ImageTransparency = 1

		paintCloned.Parent = canvas
		
		
		
		
		if num == 2 then
			num = 1
			Frame2x = paintCloned.Position.X.Offset
			Frame2y = paintCloned.Position.Y.Offset
			Frame2 = paintCloned
		else
			num = 2
			Frame1x = paintCloned.Position.X.Offset
			Frame1y = paintCloned.Position.Y.Offset
			Frame1 = paintCloned
		end
		
		
		if Frame1 and Frame2 ~= nil then
			posX = (Frame1x + Frame2x)/2
			posY = (Frame1y + Frame2y)/2




			local newLine = Instance.new("Frame")
			newLine.Position = UDim2.new(0,posX,0,posY)


			local distanceX = Frame1.AbsolutePosition.X - Frame2.AbsolutePosition.X
			local distanceY = Frame1.AbsolutePosition.Y - Frame2.AbsolutePosition.Y


			local distance = Vector2.new(distanceX,distanceY).Magnitude

			newLine.Size = UDim2.new(0,distance+10,0,size)

			local y = Frame1.AbsolutePosition.Y-Frame2.AbsolutePosition.Y
			local x = Frame1.AbsolutePosition.X - Frame2.AbsolutePosition.X

			newLine.Rotation = math.atan2(y,x)*180/math.pi

			newLine.Name = "BackgroundThing"



			newLine.AnchorPoint = Vector2.new(0.5,0.5)
			newLine.BackgroundColor3 = Color3.fromRGB(0,0,0)
			newLine.BorderSizePixel = 0
			newLine.BorderColor3 = Color3.fromRGB(0,0,0)

			local corner = Instance.new("UICorner")
			corner.CornerRadius = UDim.new(1,0)
			corner.Parent = newLine
			newLine.Parent = canvas
for i, v in pairs(canvas:GetChildren()) do
		if v:IsA("Frame") or v:IsA("ImageLabel") and v.Name ~= "DrawingFrame" then


			local vXPos, vYPos = v.Position.X.Offset, v.Position.Y.Offset

			if vXPos ~= 0 and vYPos ~= 0 then


				local newVPosX, newVPosY = convertOffPosToScaleX(vXPos), convertOffPosToScaleY(vYPos)

				v.Position = UDim2.new(newVPosX,0,newVPosY,0)
			end

			local vXSize, vYSize = v.Size.X.Offset, v.Size.Y.Offset

			if vXSize ~= 0 and vYSize ~= 0 then


				local newVSizeX, newVSizeY = convertOffPosToScaleX(vXSize), convertOffPosToScaleY(vYSize)

				v.Size = UDim2.new(newVSizeX,0,newVSizeY,0)
				
				
				
			end
			
			
			

		end
	end

Can you provide the code to your convertOFfPosToScale functions?

local function convertOffPosToScaleX(x)
	local totalX = workspace.CurrentCamera.ViewportSize.X


	local finalX = x/totalX


	return finalX
end

local function convertOffPosToScaleY(y)

	local totalY = workspace.CurrentCamera.ViewportSize.Y


	local finaly = y/totalY

	return finaly
end

Okay, I see why.

Your function is finding the scaled position as if it were parented to the main display. Instead of using ViewportSize, you need to use the AbsoluteSize of the frame that it is parented to.

So I would write:

local totalY = script.Parent.Frame.DrawingFrame.AbsoluteSize.Y

Is that correct

Yes. Let me know if there are any issues with that.

2 Likes