Advertisement
EpicGamer72

Smooth Drag LocalScript

Sep 20th, 2020
1,479
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. -- make sure this is in local script named "SmoothDrag"
  2. local Drag = script.Parent.Parent.MainFrame
  3. gsCoreGui = game:GetService("CoreGui")
  4. gsTween = game:GetService("TweenService")
  5. local UserInputService = game:GetService("UserInputService")
  6. local dragging
  7. local dragInput
  8. local dragStart
  9. local startPos
  10. local function update(input)
  11. local delta = input.Position - dragStart
  12. local dragTime = 0.04
  13. local SmoothDrag = {}
  14. SmoothDrag.Position = UDim2.new(startPos.X.Scale, startPos.X.Offset + delta.X, startPos.Y.Scale, startPos.Y.Offset + delta.Y)
  15. local dragSmoothFunction = gsTween:Create(Drag, TweenInfo.new(dragTime, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut), SmoothDrag)
  16. dragSmoothFunction:Play()
  17. end
  18. Drag.InputBegan:Connect(function(input)
  19. if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
  20. dragging = true
  21. dragStart = input.Position
  22. startPos = Drag.Position
  23. input.Changed:Connect(function()
  24. if input.UserInputState == Enum.UserInputState.End then
  25. dragging = false
  26. end
  27. end)
  28. end
  29. end)
  30. Drag.InputChanged:Connect(function(input)
  31. if input.UserInputType == Enum.UserInputType.MouseMovement or input.UserInputType == Enum.UserInputType.Touch then
  32. dragInput = input
  33. end
  34. end)
  35. UserInputService.InputChanged:Connect(function(input)
  36. if input == dragInput and dragging and Drag.Size then
  37. update(input)
  38. end
  39. end)
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement