UserInputService code from the DevHub instantly errors

The wiki writes the code as so:

local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")

local gui = script.Parent

local function moveGuiToMouse()
    local mouseLocation = UserInputService:GetMouseLocation()
    gui.Position = mouseLocation

RunService:BindToRenderStep("moveGuiToMouse", 1, moveGuiToMouse)

The documentation explains that this code is supposed to have the GUI remain in the position of the Mouse’s location at all times, but then I get this error:

It says that it won’t accept Vector2, but the wiki says otherwise.

What am I doing wrong here?

The gui’s Position is a UDim2, which takes four numbers. The mouse’s Position is a Vector2, only 2 numbers. Try gui.Position = UDim2.fromOffset(mouseLocation.X, mouseLocation.Y), which will position the ui based on the mouse’s absolute pixel location.


Looks like the Developer Hub made an oopsie. I’m surprised this hasn’t been fixed by now.

That’s not the point. THat code is directly from the wiki and it errors. The wiki is wrong.

Then put this in #platform-feedback:developer-hub, not #help-and-feedback:scripting-support. Posting the wiki’s broken code here is just going to get people to try and help find another solution for it—that’s what the category is here for, after all.


This is not an uncommon issue I have made a few requests for incorrect coding examples on the devhub and they have all been corrected, most times it happens because of simple mistakes or outdated API, if you see an error just make a post about it in the Devhub category and it will get updated quickly once the error is valid.