roblox lua gui drag

  1. Create a new ScreenGui object by using the following code: lua local gui = Instance.new("ScreenGui") gui.Parent = game.Players.LocalPlayer.PlayerGui

  2. Create a new Frame object as a child of the ScreenGui object: lua local frame = Instance.new("Frame") frame.Parent = gui

  3. Set the position and size of the Frame object using the properties Position and Size: lua frame.Position = UDim2.new(0, 100, 0, 100) frame.Size = UDim2.new(0, 200, 0, 200)

  4. Enable the Frame object to be draggable by the user by setting the Draggable property to true: lua frame.Draggable = true

  5. Add a MouseButton1Down event to the Frame object to handle the dragging functionality: ```lua frame.MouseButton1Down:Connect(function() local mouse = game.Players.LocalPlayer:GetMouse() local startPos = mouse.X local framePos = frame.Position.X.Offset

    local function updateDrag(input) local delta = input.Position.X - startPos frame.Position = UDim2.new(0, framePos + delta, 0, frame.Position.Y.Offset) end

    local function stopDrag() mouse.Move:Disconnect() mouse.Button1Up:Disconnect() end

    mouse.Move:Connect(updateDrag) mouse.Button1Up:Connect(stopDrag) end) ```

  6. Set the Visible property of the ScreenGui object to true to make it visible to the player: lua gui.Visible = true

Now you have a draggable GUI element in your Roblox game created using Lua!