It seems like you’re parenting the frame to another frame. You don’t need to do this to get the screen size. Instead, use the Camera.ViewportSize property and calculate scale based on that.
local mousePos = UserInputService:GetMouseLocation()
local viewportSize = Camera.ViewportSize
local scalePosition = UDim2.fromScale(mousePos.X / viewportSize.X, mousePos.Y / viewportSize.Y)
That wouldn’t achieve what I want. I want the frame to position itself to the mouse position even if the frame is inside another frame that is small. That code does follow the mouse but it keeps itself inside the parent.
GetMouselocation does not account for GuiInset. You’re seeing ~60 pixel gap between where it is and where it’s supposed to be. To fix this, you have to manually account for the GuiInset with GuiService:GetGuiInset():
local targetPos = mouseLocation - parent.AbsolutePosition - GuiService:GetGuiInset()