Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 8 years ago
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

Log in to vote
0
Answered by 8 years ago

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.

Ad

Answer this question