Advertisement
Scriptorz5

Good dragging

Nov 16th, 2019
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. function dragify(Main)
  2. dragToggle = nil
  3. dragSpeed = .25 -- You can edit this.
  4. dragInput = nil
  5. dragStart = nil
  6. dragPos = nil
  7.  
  8. function updateInput(input)
  9. Delta = input.Position - dragStart
  10. Position = UDim2.new(startPos.X.Scale, startPos.X.Offset + Delta.X, startPos.Y.Scale, startPos.Y.Offset + Delta.Y)
  11. game:GetService("TweenService"):Create(Main, TweenInfo.new(dragSpeed), {Position = Position}):Play()
  12. end
  13.  
  14. Main.InputBegan:Connect(function(input)
  15. if (input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch) then
  16. dragToggle = true
  17. dragStart = input.Position
  18. startPos = Main.Position
  19. input.Changed:Connect(function()
  20. if (input.UserInputState == Enum.UserInputState.End) then
  21. dragToggle = false
  22. end
  23. end)
  24. end
  25. end)
  26.  
  27. Main.InputChanged:Connect(function(input)
  28. if (input.UserInputType == Enum.UserInputType.MouseMovement or input.UserInputType == Enum.UserInputType.Touch) then
  29. dragInput = input
  30. end
  31. end)
  32.  
  33. game:GetService("UserInputService").InputChanged:Connect(function(input)
  34. if (input == dragInput and dragToggle) then
  35. updateInput(input)
  36. end
  37. end)
  38. end
  39.  
  40. dragify(Main)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement