GetMouseLocation Example Code Broken

The example code snippet on the page for UserInputService:GetMouseLocation is broken.

This snippet attempts to move a GUI to the mouse location. However, the value returned by GetMouseLocation is a Vector2, while all GUI objects expect a UDim2 for their Position property.

This results in the following error being produced every frame:


Affected article:


Thank you for reporting this! I’ve just added it to our todo backlog.

Update: the code sample has been fixed - the change should be visible soon. For anyone searching for this problem, change line 7 from this:

    gui.Position = mouseLocation

to this:

    gui.Position =, mouseLocation.X, 0, mouseLocation.Y)

Since you’re using 0 values for both scales, I’d assume fromOffset is also appropriate to use here? Possibly even canonical?

gui.Position = UDim2.fromOffset(mouseLocation.X, mouseLocation.Y)
1 Like