Advertisement
DrawingJhon

Resizable Frame

Dec 13th, 2020 (edited)
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.32 KB | None | 0 0
  1. local player = game:GetService("Players").LocalPlayer
  2. local UIS = game:GetService("UserInputService")
  3. local mouse = player:GetMouse()
  4. local g = Instance.new("ScreenGui", script)
  5. g.Name = "Resizable"
  6. local frame = Instance.new("Frame", g)
  7. frame.Name = "Main"
  8. frame.Size = UDim2.new(0, 300, 0, 200)
  9. frame.Position = UDim2.new(0, 300, 0, 500)
  10. local buttonY = Instance.new("TextButton", frame)
  11. buttonY.Name = "Button"
  12. buttonY.Text = ""
  13. buttonY.Size = UDim2.new(1, 0, 0, 30)
  14. local pressing = false
  15. local lastY = 0
  16. local lastX = 0
  17. local minY = 571
  18. local maxY = 147
  19. local minX = 150
  20. local maxX = 650
  21.  
  22. buttonY.InputBegan:Connect(function(input)
  23.     if input.UserInputType == Enum.UserInputType.MouseButton1 then
  24.         pressingY = true
  25.         lastY = (mouse.Y - frame.Position.Y.Offset)
  26.         lastX = (mouse.X - frame.Position.X.Offset)
  27.     end
  28. end)
  29.  
  30. UIS.InputEnded:Connect(function(input)
  31.     if input.UserInputType == Enum.UserInputType.MouseButton1 then
  32.         pressingY = false
  33.     end
  34. end)
  35.  
  36. mouse.Move:Connect(function()
  37.     if pressingY then
  38.         local resultY = mouse.Y - lastY
  39.         local x, y = mouse.X, math.min(math.max(resultY, maxY), minY)
  40.         local sizeY = frame.Size.Y.Offset
  41.         local posY = frame.Position.Y.Offset
  42.         local newNum = posY - y
  43.         frame.Position = UDim2.new(0, 300, 0, y)
  44.         frame.Size = UDim2.new(0, 300, 0, sizeY + newNum)
  45.     end
  46. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement