Advertisement
Ubicast

Smooth Drag Script | ROBLOX

Nov 21st, 2020
709
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.42 KB | None | 0 0
  1. local Object = script.Parent
  2.  
  3. local UserInputService = game:GetService("UserInputService")
  4. local SmoothDragSpeed = 0.1
  5.  
  6. local SmoothDragToggle
  7. local SmoothDragInput
  8. local SmoothDragStart
  9.  
  10. function SmoothDrag(Frame)
  11.  
  12.     local function UpdateSmoothDragInput(Input)
  13.         local Delta = Input.Position - SmoothDragStart
  14.         local Position = UDim2.new(startPos.X.Scale, startPos.X.Offset + Delta.X, startPos.Y.Scale, startPos.Y.Offset + Delta.Y)
  15.         game:GetService("TweenService"):Create(Frame, TweenInfo.new(SmoothDragSpeed), {Position = Position}):Play()
  16.     end
  17.  
  18.     Frame.InputBegan:Connect(function(Input)
  19.         if (Input.UserInputType == Enum.UserInputType.MouseButton1 or Input.UserInputType == Enum.UserInputType.Touch) and UserInputService:GetFocusedTextBox() == nil then
  20.             SmoothDragToggle = true
  21.             SmoothDragStart = Input.Position
  22.             startPos = Frame.Position
  23.             Input.Changed:Connect(function()
  24.                 if Input.UserInputState == Enum.UserInputState.End then
  25.                     SmoothDragToggle = false
  26.                 end
  27.             end)
  28.         end
  29.     end)
  30.  
  31.     Frame.InputChanged:Connect(function(Input)
  32.         if Input.UserInputType == Enum.UserInputType.MouseMovement or Input.UserInputType == Enum.UserInputType.Touch then
  33.             SmoothDragInput = Input
  34.         end
  35.     end)
  36.  
  37.     game:GetService("UserInputService").InputChanged:Connect(function(Input)
  38.         if Input == SmoothDragInput and SmoothDragToggle then
  39.             UpdateSmoothDragInput(Input)
  40.         end
  41.     end)
  42.  
  43. end
  44.  
  45. SmoothDrag(Object)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement