How to make an dragable gui

I want to do a dragable gui like this:

https://gyazo.com/19a823b007db478f4e962a64f89deba2

How can i do that

Note there are better ways to do this but this is what i usually use

local mousedown = false
game.Players.LocalPlayer:GetMouse().Button1Down:Connect(function()
	mousedown = true
end)
game.Players.LocalPlayer:GetMouse().Button1Up:Connect(function()
	mousedown = false
end)
local relativeToFrame
local mouse = game.Players.LocalPlayer:GetMouse()

while true do
	wait()
	if game.Players.LocalPlayer:GetMouse().X > (script.Parent.Frame.AbsolutePosition.X) and game.Players.LocalPlayer:GetMouse().X < (script.Parent.Frame.AbsolutePosition.X + script.Parent.Frame.AbsoluteSize.X) and game.Players.LocalPlayer:GetMouse().Y > (script.Parent.Frame.AbsolutePosition.Y) and game.Players.LocalPlayer:GetMouse().Y < (script.Parent.Frame.AbsolutePosition.Y + script.Parent.Frame.AbsoluteSize.Y)  then
		
		if mousedown == true then
			relativeToFrame = Vector2.new(script.Parent.Frame.AbsolutePosition.X - mouse.X,script.Parent.Frame.AbsolutePosition.Y - mouse.Y)
			while mousedown do
				wait()
				if not mousedown then break end
				script.Parent.Frame.Position = UDim2.new(0,mouse.X + relativeToFrame.X,0, mouse.Y + relativeToFrame.Y)
			end
		end
	else
		
	end
	--[[print((script.Parent.Frame.AbsolutePosition.X + script.Parent.Frame.AbsoluteSize.X))
		print(script.Parent.Frame.AbsolutePosition.X)
		print(game.Players.LocalPlayer:GetMouse().X)]]
end

This will be a LocalScript parented to the Frame

local MS = game.Players.LocalPlayer:GetMouse()
local Offset

script.Parent.InputBegan:Connect(function(Input)
    if Input.UserInputType == Enum.UserInputType.MouseButton1 then
        Offset = script.Parent.AbsolutePosition - Vector2.new(MS.X,MS.Y)
    end
end)

script.Parent.InputEnded:Connect(function(Input)
    if Input.UserInputType == Enum.UserInputType.MouseButton1 then
        Offset = nil
    end
end)

MS.Move:Connect(function()
    if Offset then
        script.Parent.Position = UDim2.fromOffset(MS.X + Offset.X,MS.Y + Offset.Y)
    end
end)

Make sure AnchorPoint is 0,0.

1 Like