Advertisement
Dully

make gui draggable

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