Advertisement
whiteyume

Untitled

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