How can I convert this to offset?

I am currently doing math to calculate where my mouse “icon” should be, but I am using a imagelabel because I have to in this case, currently I can only get the scale but I need to convert it to offset since it is not accurately on the mouse.

Here is my code

local X = Mouse.X / GUI.AbsoluteSize.X
		local Y = Mouse.Y / GUI.AbsoluteSize.Y
		
		local offsetX = UDim2.new(0, Canvas.AbsolutePosition.X*Canvas.Position.X.Scale+Canvas.Position.X.Offset, 0)
		local offsetY = UDim2.new(0, Canvas.AbsolutePosition.Y*Canvas.Position.Y.Scale+Canvas.Position.Y.Offset, 0)

scale * workspace.CurrentCamera.ViewportSize

This is using UI why would getting the viewport help, please explain thanks :slight_smile:

Because the mouse’s position is in the Viewport.

I am just using :getmouse() since I am dealing with ALL ui is it just to find how big the screen is? That is the only thing I can think of

1 Like

If I understand correctly you are trying to have an ImageLabel in the same location as the mouse.

You can use Mouse.X and Mouse.Y, those values are the number of pixels offset from the top left corner.

The Viewport Size is the amount of pixels the entire game window is. You can it by doing CurrentCamera.ViewportSize.

If you want to find the offset of a UI you can do, scale * UI.AbsolutePosition, but you shouldn’t need that for this case just put the UI in the same X and Y as Mouse.

1 Like

UDim2 values also require 4 components, in your script both UDim2.new() calls only contain 3.