How can I move a Frame with the mouse position when clicking a textButton?

Well, this mouse is complicated for me since I have not seen this many times and when I need it I ask for help. Well, I have a problem with changing the position of the Frame when clicking the textbutton, obtaining the location of the mouse and putting that position to the frame, the problem is that the frame is left the screen and I don’t know what to do to solve it


local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Button = script.Parent

local Mouse = Player:GetMouse()

local GetFrame = script.Parent.Parent:WaitForChild("Frame")

Button.MouseButton1Click:Connect(function()
	GetFrame.Position = UDim2.new(Mouse.X, 0, Mouse.Y, 0)
end)
2 Likes

Change this to
GetFrame.Position = UDim2.new(0, Mouse.X,0, Mouse.Y)

1 Like

Mouse.X and Mouse.Y are in pixels.

GetFrame.Position = UDim2.new(0, Mouse.X, 0, Mouse.Y)

You gave him the same code? you have fixed your post.

1 Like

I just forgot to change it ;-; but now its right.

1 Like

I know I also thought about that but I thought it was not a good option

Its the only way to achieve your task.

once I saw a script that changed the position well from scale and not from offset (I tried it but lost the script)

Just change what I said and everything will be ok.

1 Like