local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Mouse = Player:GetMouse()
local PlayerGui = Player:WaitForChild("PlayerGui")
local ScreenGui = PlayerGui:WaitForChild("ScreenGui")
local MyButton = ScreenGui:WaitForChild("Button")
local MovingFrame = MyButton:WaitForChild("Frame")
MyButton.MouseButton1Click:Connect(function()
local positionToAssign = UDim2.new(0, Mouse.X, 0, Mouse.Y)
MovingFrame.Position = positionToAssign
end)
Also, make sure your MovingFrame has an Anchor Point property of Vector2<.5, .5>. Let me know if this doesn’t achieve a better result and I think I know another solution.
The MovingFrame instance in my example must be removed as a child of the button instance. It must instead be another child of the ScreenGui. This is likely the issue since calculated position is relative to the parent within which a Gui Instance is rendered. If I re-did the hierarchy I would do this:
ScreenGui → Children: Frame of Size UDim2.new(1, 0, 1, 0) → Children of full-screen frame: Button and MovingFrame