Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Having trouble moving a Frame to the Position of the Mouse/Cursor?

local plyr = game:GetService("Players").LocalPlayer
local mouse = plyr:GetMouse()
local Frame =  plyr.PlayerGui.ScreenGui.Frame
Frame.Visible = true

while true do
	wait()
	Frame.Position = (mouse.Hit)
end

In this LocalScript it changes the frame to visible but does not move it to the mouse position. I Read on the Roblox Wiki that "Hit" is "The position of where the mouse is pointing." so i tried to do this myself but failed :3

Hope Sombody can help, Thanks.

1 answer

✓ Accepted answer

There are multiple reasons it errored:

  • A gui requires a UDim2 Value to change the position
  • To get a CFrame you need to do mouse.Hit.p

#UDim2 This is like Vector2. There is an X and Y axis. UDim2 also has an X and Y axis but the main difference is that there are things called Scale and Offset.

UDim2.new(0,1,1,0) --Would show up like this {0,1},{1,0}

#Final Product

local plyr = game:GetService("Players").LocalPlayer
local mouse = plyr:GetMouse()
local Frame =  plyr.PlayerGui.ScreenGui.Frame
Frame.Visible = true

mouse.Move:connect(function()
    Frame.Position = UDim2.new(0,mouse.X,0,mouse.Y)
end)

Hope it helps!


#Note: The gui will be in a weird position, it's just how ROBLOX is.

This discussion is preserved as it was. New answers, comments, and votes are closed.