So, I’ve been trying to make a spray can tool that let’s you spray decals on any surface. I want it to align with the surface while also rotating on the Y axis in order to look at the player who sprayed it.
The code for the positioning is below and the size of the part is {5, 0.2, 5}. The problem with the code is that it only seems to work half way… Here’s an image to see what I mean: Screenshot by Lightshot It works on the left side and correctly adjusts the Y axis to look at me, but when it get’s too far to the right it does a 360 until it get’s to the left again and is normal. I’ve tried other methods and nothing has worked, the solution is most likely easy but this isn’t my strong suit so yeah… Please help if you can.
local function calculateSprayInfo()
-- Get needed spray information and send it off to the server.
local newRay = Ray.new(Camera.CFrame.p, (Mouse.Hit.p - Camera.CFrame.p).unit * 200)
local _, Pos, surfaceNormal = workspace:FindPartOnRay(newRay)
local Torso = Character:FindFirstChild("Torso")
if not Torso then return end
local sprayCFrame = CFrame.new(Pos, Pos - surfaceNormal) * CFrame.Angles(-90 * math.pi/180, 0, 0)
local lookAt = CFrame.new(sprayCFrame.p, Torso.Position)
local cx, cy, cz = sprayCFrame:toEulerAnglesXYZ()
local lx, ly, lz = lookAt:toEulerAnglesXYZ()
sprayCFrame = CFrame.new(sprayCFrame.p) * CFrame.Angles(cx, ly, 0)
sprayEvent:FireServer(assetId, decayTime, spraySize, sprayCFrame)
end