Be_Gone_Thot

Drag Function made by Google Chrome

Sep 20th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. --//ALL CREDITS GO TO Google Chrome\\--
  2.  
  3. local players = game:service('Players');
  4. local player = players.LocalPlayer;
  5. local mouse = player:GetMouse();
  6. local run = game:service('RunService');
  7. local stepped = run.Stepped;
  8. draggable = function(obj)
  9. spawn(function()
  10. obj.Active = true;
  11. local minitial;
  12. local initial;
  13. local isdragging;
  14. obj.InputBegan:Connect(function(input)
  15. if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
  16. isdragging = true;
  17. minitial = input.Position;
  18. initial = obj.Position;
  19. local con;
  20. con = stepped:Connect(function()
  21. if isdragging then
  22. local delta = Vector3.new(mouse.X, mouse.Y, 0) - minitial;
  23. obj.Position = UDim2.new(initial.X.Scale, initial.X.Offset + delta.X, initial.Y.Scale, initial.Y.Offset + delta.Y);
  24. else
  25. con:Disconnect();
  26. end;
  27. end);
  28. input.Changed:Connect(function()
  29. if input.UserInputState == Enum.UserInputState.End then
  30. isdragging = false;
  31. end;
  32. end);
  33. end;
  34. end);
  35. end)
  36. end;
  37.  
  38. draggable(script.Parent)
Add Comment
Please, Sign In to add comment