RBX_pross_fan440872

Dragify

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