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)
COMMUNITY QUESTION
how can i make a gui that you can drag like a window?
1 answer
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!
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
gui.Draggable = true lmao