Advertisement
Joriangames

Drag Frame LocalScript

Apr 26th, 2022
2,429
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.39 KB | None | 0 0
  1. --[[
  2. Thanks for using this script
  3. Want to know how to use this and script explanation?
  4. Check out my video here: https://youtu.be/aCs3f-nVWrE
  5.  
  6. ]]
  7.  
  8. --Don't forget to subscribe for more!
  9. --Ask your questions in the comments from: https://youtu.be/aCs3f-nVWrE
  10. --Tutorial by BloxianCode
  11. local UIS = game:GetService("UserInputService")
  12.  
  13. local draggableFrame = script.Parent
  14.  
  15. local IsDragging = false    --checks if the player is dragging the frame
  16. local dragInput             --input variable which we will use later
  17. local StartingPoint
  18. local oldPos                --Old position from the frame
  19.  
  20. local function update(input)
  21.     local delta = input.Position - StartingPoint
  22.     draggableFrame.Position = UDim2.new(oldPos.X.Scale, oldPos.X.Offset + delta.X, oldPos.Y.Scale, oldPos.Y.Offset + delta.Y)
  23. end
  24.  
  25. draggableFrame.InputBegan:Connect(function(input)
  26.     if input.UserInputType == Enum.UserInputType.MouseButton1 then
  27.         IsDragging = true
  28.         StartingPoint = input.Position
  29.         oldPos = draggableFrame.Position
  30.  
  31.         input.Changed:Connect(function()
  32.             if input.UserInputState == Enum.UserInputState.End then
  33.                 IsDragging = false
  34.             end
  35.         end)
  36.     end
  37. end)
  38.  
  39. draggableFrame.InputChanged:Connect(function(input)
  40.     if input.UserInputType == Enum.UserInputType.MouseMovement then
  41.         dragInput = input
  42.     end
  43. end)
  44.  
  45. UIS.InputChanged:Connect(function(input)
  46.     if input == dragInput and IsDragging then
  47.         update(input)
  48.     end
  49. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement