Advertisement
Pro_Pastebin_Person1

Untitled

Apr 18th, 2020
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. local API = {}
  2.  
  3. function API:Load()
  4.  
  5. local other = {}
  6. function other:CustomDrag(Object, Delay)
  7. local UserInputService = game:GetService("UserInputService")
  8.  
  9. local gui = Object
  10.  
  11. local dragging
  12. local dragInput
  13. local dragStart
  14. local startPos
  15.  
  16. local function update(input)
  17. local delta = input.Position - dragStart
  18. wait(tonumber(Delay))
  19. gui.Position = UDim2.new(startPos.X.Scale, startPos.X.Offset + delta.X, startPos.Y.Scale, startPos.Y.Offset + delta.Y)
  20. end
  21.  
  22. gui.InputBegan:Connect(function(input)
  23. if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
  24. dragging = true
  25. dragStart = input.Position
  26. startPos = gui.Position
  27.  
  28. input.Changed:Connect(function()
  29. if input.UserInputState == Enum.UserInputState.End then
  30. dragging = false
  31. end
  32. end)
  33. end
  34. end)
  35.  
  36. gui.InputChanged:Connect(function(input)
  37. if input.UserInputType == Enum.UserInputType.MouseMovement or input.UserInputType == Enum.UserInputType.Touch then
  38. dragInput = input
  39. end
  40. end)
  41.  
  42. UserInputService.InputChanged:Connect(function(input)
  43. if input == dragInput and dragging then
  44. update(input)
  45. end
  46. end)
  47. end
  48. function other:OnButtonPress(Button, Callback)
  49. if Button:IsA("TextButton") then
  50. Button.MouseButton1Click:Connect(function()
  51. Callback()
  52. end)
  53. elseif Button:IsA("ImageButton") then
  54. Button.MouseButton1Click:Connect(function()
  55. Callback()
  56. end)
  57. else
  58. warn("Please make sure you define a button!")
  59. end
  60. end
  61.  
  62. return other;
  63. end
  64.  
  65. return API;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement