Advertisement
9_cVv

dragify

Mar 26th, 2021
1,090
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.21 KB | None | 0 0
  1. function dragify(Frame)
  2.     local dragToggle = nil
  3.     local dragSpeed = .25
  4.     local dragInput = nil
  5.     local dragStart = nil
  6.     local dragPos = nil
  7.    
  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(.25), {Position = Position}):Play()
  12.     end
  13.    
  14.     Frame.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 = Frame.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.     Frame.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. return dragify
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement