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

how can i make a gui that you can drag like a window?

Asked by 3 years ago

i am making a gui, and i want to drag it like a window(like dragging the title bar and it moves to the mouse). how can I do this? (and i want it to stop moving after you stop holding the mouse)

0
gui.Draggable = true lmao greatneil80 2647 — 3y

1 answer

Log in to vote
0
Answered by
4jnx 50
3 years ago

Hello there!

So if you want your GUI be draggable i would NOT recommend the frame.Draggable property as it is depreciated and dragging is clunky and broken

BUT

I do have my own script for making a draggable frame that works pretty well!

local UserInputService = game:GetService("UserInputService")

local Frame = script.Parent

local dragging
local dragInput
local dragStart
local startPos

local function update(input)
  local delta = input.Position - dragStart
  Frame.Position = UDim2.new(startPos.X.Scale, startPos.X.Offset + delta.X, startPos.Y.Scale, startPos.Y.Offset + delta.Y)
end

Frame.InputBegan:Connect(function(input)
  if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
    dragging = true
    dragStart = input.Position
    startPos = Frame.Position

    input.Changed:Connect(function()
      if input.UserInputState == Enum.UserInputState.End then
        dragging = false
      end
    end)
  end
end)

Frame.InputChanged:Connect(function(input)
  if input.UserInputType == Enum.UserInputType.MouseMovement or input.UserInputType == Enum.UserInputType.Touch then
    dragInput = input
  end
end)

UserInputService.InputChanged:Connect(function(input)
  if input == dragInput and dragging then
    update(input)
  end
end)

Hope this helped!

Ad

Answer this question