Axolotleless

ScreenGui drawing system!

Jan 31st, 2025
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.42 KB | None | 0 0
  1. local player = game.Players.LocalPlayer
  2.  
  3. local frame = script.Parent
  4.  
  5. local dragging = false
  6.  
  7. -- turn on dragging when the mouse is pressed or the screen is touched
  8. frame.InputBegan:Connect(function(input)
  9.     if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
  10.         dragging = true
  11.     end
  12. end)
  13.  
  14. -- turn off dragging when its released
  15. frame.InputEnded:Connect(function(input)
  16.     if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
  17.         dragging = false
  18.     end
  19. end)
  20.  
  21. -- helper function to draw one point at the given x,y position
  22.     local function DrawAt(x, y)
  23.         -- need the parent's position so we can subtract it from the child's
  24.         local topLeft = frame.AbsolutePosition
  25.        
  26.         local point = Instance.new("Frame")
  27.         point.BackgroundColor3 = Color3.fromRGB(0,0,0)
  28.         point.Size = UDim2.fromOffset(5, 5)
  29.         point.Position = UDim2.fromOffset(x - topLeft.X - 5, y - topLeft.Y - 5)
  30.         point.Parent = frame
  31.        
  32.     end
  33.    
  34.     -- fired when the mouse or finger moves
  35.     frame.InputChanged:Connect(function(input)
  36.         if dragging and input.UserInputType == Enum.UserInputType.MouseMovement or input.UserInputType == Enum.UserInputType.Touch then
  37.             DrawAt(input.Position.X, input.Position.Y)
  38.         end
  39.     end)
  40.    
Advertisement
Add Comment
Please, Sign In to add comment