Advertisement
SigmaBoy456

Dragging GUI Example 👓🕶️

Sep 20th, 2024 (edited)
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.24 KB | None | 0 0
  1. local function Dragging(TargetFrame)
  2.     local dragging = false
  3.     local dragInput, dragStart, startPos
  4.  
  5.     local function update(input)
  6.         local delta = input.Position - dragStart
  7.         TargetFrame.Position = UDim2.new(startPos.X.Scale, startPos.X.Offset + delta.X, startPos.Y.Scale, startPos.Y.Offset + delta.Y)
  8.     end
  9.  
  10.     TargetFrame.InputBegan:Connect(function(input)
  11.         if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
  12.             dragging = true
  13.             dragStart = input.Position
  14.             startPos = TargetFrame.Position
  15.  
  16.             input.Changed:Connect(function()
  17.                 if input.UserInputState == Enum.UserInputState.End then
  18.                     dragging = false
  19.                 end
  20.             end)
  21.         end
  22.     end)
  23.  
  24.     TargetFrame.InputChanged:Connect(function(input)
  25.         if input.UserInputType == Enum.UserInputType.MouseMovement or input.UserInputType == Enum.UserInputType.Touch then
  26.             dragInput = input
  27.         end
  28.     end)
  29.  
  30.     game:GetService("UserInputService").InputChanged:Connect(function(input)
  31.         if input == dragInput and dragging then
  32.             update(input)
  33.         end
  34.     end)
  35. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement