Advertisement
Axolotleless

Spray paint system

Feb 3rd, 2025
962
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.23 KB | None | 0 0
  1. local mouse = game.Players.LocalPlayer:GetMouse()
  2. local isMouseOnHold = false
  3. local isEquipped = false
  4.  
  5.  
  6. function getAngleBetween(u, v, axis)
  7.     local dot, uxv = u:Dot(v), u:Cross(v)
  8.     if dot < -0.99999 then return CFrame.fromAxisAngle(axis, math.pi) end
  9.     return CFrame.new(0,0,0, uxv.x, uxv.y, uxv.z, 1+dot)
  10. end
  11.  
  12. script.Parent.Unequipped:Connect(function()
  13.     isEquipped = false
  14. end)
  15.  
  16. script.Parent.Equipped:Connect(function()
  17.     isEquipped = true
  18.     mouse.Button1Down:Connect(function()
  19.         isMouseOnHold = true
  20.     end)
  21.     mouse.Button1Up:Connect(function()
  22.         isMouseOnHold = false
  23.     end)
  24. end)
  25.  
  26. local paints = {}
  27.  
  28. mouse.Move:Connect(function()
  29.     if isMouseOnHold and isEquipped then
  30.         local ro = workspace.CurrentCamera.CFrame.Position
  31.         local raycastParams = RaycastParams.new()
  32.         raycastParams.FilterDescendantsInstances = paints
  33.         local raycastResults = workspace:Raycast(ro, mouse.UnitRay.Direction*1000, raycastParams)
  34.         if raycastResults then
  35.             local p = Instance.new("Part", workspace.Debris)
  36.             p.Size = Vector3.new(1,0.25,1)
  37.             p.Anchored = true
  38.             p.CFrame = getAngleBetween(p.CFrame.UpVector, raycastResults.Normal, ro)
  39.             p.Position = mouse.Hit.Position
  40.             p.CanCollide = false
  41.             table.insert(paints, p)
  42.         end
  43.     end
  44. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement