Incorrect Y position GetMouseLocation()

UDim2.new((UserInputService:GetMouseLocation().X - script.Parent.AbsolutePosition.X) / script.Parent.AbsoluteSize.X, 0, ((UserInputService:GetMouseLocation().Y - script.Parent.AbsolutePosition.Y) / script.Parent.AbsoluteSize.Y) - ("Y is messed up subtract with what?"), 0))

I’m trying to get the position of a mouse when clicked inside of a GUI object but the Y position is always wrong IgnoreGUIInset is off so I have no clue what the problem is

Because .AbsolutePosition starts beneath the topbar instead of at the corner of the screen

1 Like

What else can I do differently then?

math.

get the GUI inset value and add it to the AbsolutePosition so that it starts at 0,0 when at the corner of the screen.

Example code

local uis = game:GetService('UserInputService')
local gus = game:GetService('GuiService')
local frame = script.Parent

game:GetService('RunService').RenderStepped:Connect(function()
	local origin: Vector2 = frame.AbsolutePosition + gus:GetGuiInset()
	local relative: Vector2 = uis:GetMouseLocation() - origin
	local alpha: Vector2 = relative / frame.AbsoluteSize
	print(alpha)
end)

didnt even know :GetGuiInset() existed thanks

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.