I have been trying to make it where the bullets have spread, but I keep getting the same error again and again saying where the direction is, "attempt to perform arithmetic (umn) on nil. Any way to fix this? I just don’t get this.
(MousePosition is mouse.hit.p and BarrelPos is the orgin of the raycast.)
local Spread = Module.Spread
local Direction = (CFrame.new(BarrelPos,MousePosition) * CFrame.Angles(math.rad(-Spread+(math.random()*(Spread*2))),math.rad(-Spread+(math.random()*(Spread*2))),0)).lookVector
Please separate your CFrame statements like so below.
local Spread = Module.Spread
local xAxisRotation = math.rad(-Spread+(math.random()*(Spread*2)))
local yAxisRotation = math.rad(-Spread+(math.random()*(Spread*2)))
local spreadRotationCF = CFrame.Angles(xAxisRotation,yAxisRotation,0)
local initialDirectionCF = CFrame.new(BarrelPos,MousePosition)
local Direction = (initialDirectionCF*spreadRotationCF).lookVector
Now you can debug further to see which specific math related line has a variable becoming nil instead of that one specific really long line. I’m guessing Module.Spread is equal to nil somehow causing the arithmetic error.