DrawingJhon

Draggable gui

Jul 26th, 2020 (edited)
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.68 KB | None | 0 0
  1. local hazDrag = false
  2.  
  3. local function makeDrag(frame)
  4. local mouse = owner:GetMouse()
  5. local mouseButton1, Touch = Enum.UserInputType.MouseButton1, Enum.UserInputType.Touch
  6.  
  7. local pressing = false
  8.  
  9. local con1
  10. local con2
  11. con1 = frame.InputBegan:connect(function(input)
  12.     pressing = true
  13.     local lastPosition
  14.     local dis = UDim2.new(0, mouse.X, 0, mouse.Y) - frame.Position
  15.     local loop
  16.     if input.UserInputType == mouseButton1 or input.UserInputType == Touch then
  17.         loop = game:GetService("RunService").RenderStepped:Connect(function()
  18.             if pressing == false then loop:Disconnect() return end
  19.             local pos = UDim2.new(0, mouse.X, 0, mouse.Y) - dis
  20.             if pos == lastPosition then return else lastPosition = pos end
  21.             frame:TweenPosition(pos, "Out", "Sine", 0.1, true)
  22.         end)
  23.     end
  24.     if input.KeyCode == Enum.KeyCode.X then
  25.         frame:Destroy()
  26.         con1:Disconnect()
  27.         con2:Disconnect()
  28.     end
  29. end)
  30. con2 = game:GetService("UserInputService").InputEnded:Connect(function(input)
  31.     if input.UserInputType ~= mouseButton1 and input.UserInputType ~= Touch then return end
  32.     pressing = false
  33. end)
  34. end
  35.  
  36. for _, child in pairs(owner.PlayerGui:GetDescendants()) do
  37.     if child.Name == "DragZZ" then
  38.         if child.ClassName == "Frame" or child.ClassName == "TextButton" or child.ClassName == "TextLabel" or child.ClassName == "ImageLabel" then
  39.             hazDrag = true
  40.             makeDrag(child)
  41.         end
  42.     end
  43. end
  44.  
  45. if hazDrag then return end
  46. local screen = Instance.new("ScreenGui", owner.PlayerGui)
  47. screen.Name = "DrGui"
  48. local frame = Instance.new("TextLabel", screen)
  49. frame.Text = "BRUH"
  50. frame.Font = "Cartoon"
  51. frame.TextScaled = true
  52. frame.Name = "Draggable"
  53. frame.Size = UDim2.new(0, 200, 0, 100)
  54.  
  55. makeDrag(frame)
Add Comment
Please, Sign In to add comment