Advertisement
rrixh

draggle UI

Jun 16th, 2023
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. local UIS = game:GetService("UserInputService")
  2.  
  3. local draggableFrame = script.Parent
  4.  
  5. local IsDragging = false
  6. local dragInput
  7. local StartingPoint
  8.  
  9.  
  10. local oldPos
  11. local function update(input)
  12. local delta = input.Position - StartingPoint
  13. draggableFrame.Position = UDim2.new(oldPos.X.Scale, oldPos.X.Offset + delta.X, oldPos.Y.Scale, oldPos.Y.Offset + delta.Y)
  14. end
  15.  
  16. draggableFrame.InputBegan:Connect(function(input)
  17. if input.UserInputType == Enum.UserInputType.MouseButton1 then
  18. IsDragging = true
  19. StartingPoint = input.Position
  20. oldPos = draggableFrame.Position
  21.  
  22. input.Changed:Connect(function()
  23. if input.UserInputState == Enum.UserInputState.End then
  24. IsDragging = false
  25. end
  26. end)
  27. end
  28. end)
  29.  
  30. draggableFrame.InputChanged:Connect(function(input)
  31. if input.UserInputType == Enum.UserInputType.MouseMovement then
  32. dragInput = input
  33. end
  34. end)
  35.  
  36. UIS.InputChanged:Connect(function(input)
  37. if input == dragInput and IsDragging then
  38. update(input)
  39. end
  40. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement