How would I make a UI draggable?

How would I make it so that a player can drag a frame?

and size it?

1 Like

This is a Code I used from my old game:

local UIS = game:GetService("UserInputService")
 
local draggableFrame = script.Parent
 
local IsDragging = false    
local dragInput          
local StartingPoint
local oldPos                
 
local function update(input)
    local delta = input.Position - StartingPoint
    draggableFrame.Position = UDim2.new(oldPos.X.Scale, oldPos.X.Offset + delta.X, oldPos.Y.Scale, oldPos.Y.Offset + delta.Y)
end
 
draggableFrame.InputBegan:Connect(function(input)
    if input.UserInputType == Enum.UserInputType.MouseButton1 then
        IsDragging = true
        StartingPoint = input.Position
        oldPos = draggableFrame.Position
 
        input.Changed:Connect(function()
            if input.UserInputState == Enum.UserInputState.End then
                IsDragging = false
            end
        end)
    end
end)
 
draggableFrame.InputChanged:Connect(function(input)
    if input.UserInputType == Enum.UserInputType.MouseMovement then
        dragInput = input
    end
end)
 
UIS.InputChanged:Connect(function(input)
    if input == dragInput and IsDragging then
        update(input)
    end
end)

Thats a lot a lot to take in, is their a simpler way to preform this without more than 20 lines of code?

Maybe, I’m not 100% Sure Though
if You are going to use it then the script will be like the Size But you gotta change some stuff for it to work with the Size.

There is a way with 4 lines of code though it is deprecated meaning it’s unsupported…
It’s also a bit buggy and cane be hard to use

local Frame = "Get Frame Here"

Frame.Active = true
Frame.Selectable = true
Frame.Draggable = true

It should work though as I said it can be buggy xP

Idk about sizing though…

The Draggable property has been deprecated, do not use it. Also, you can’t define a frame instance through a string.

As I said above it has been deprecated but it still works. It’s just not being updated or supported anymore so it’s less effective.

As it still being useable it is the easiest methob but not the best.

My way works well, But it takes space so.

I also said above get the frame here not put the name or smthing

Your way is the most effective, it was written by a roblox administrator just after the draggable property was deprecated

Should’ve commented that to make it easier for others who may not seem to understand what you meant (me).

Is their a method thats up to date and easy?

The one that @lilmazen1234 replied with is the most up to date and easy. It looks challenging but it works and it is the most efficient

Sorry for the mis-confusion lol

https://devforum.roblox.com/t/simple-module-for-creating-draggable-gui-elements/

Same as/similar to first reply.

1 Like

Draggable still works as it always has.

Just copy and paste???
Why would the number of code lines matter?

For me at least, the smaller the code is, the more simplified it is for me.

Also, copying and pasting isn’t learning at all if you have common sense, Im never gonna learn if I just copy and paste.

No offense.

try this Resize and drag GUI objects using this module!