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

Hi, I'm making a GUI right now, but I want it to be draggable, Help me?

Asked by 6 years ago

Hi, I'm making a GUI right now, but I want it to be dragable, but the current script I have isn't working.

frame = script.Parent.Frame
frame.Draggable = true

-- Draggable Frame

Could you help me?

0
If that doesn't work try moving the frame when the mouse moves via UserInputService.InputBegan User#19524 175 — 6y
0
What does that mean? I just a learner scripter xD Starnamics 24 — 6y
0
Ok, I fixed it. Starnamics 24 — 6y
0
If so edit your title so it contains [SOLVED] so people know it has been solved. User#19524 175 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

Draggable has sadly Removed. but you can use this:

local UserInputService = game:GetService("UserInputService")

local gui = script.Parent

local dragging
local dragInput
local dragStart
local startPos

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

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

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

gui.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)

you should add this script in specific object. (from https://devforum.roblox.com/t/draggable-property-is-hidden-on-gui-objects/107689/4)

Ad

Answer this question