I wanna make a gun that shoots with a random spray pattern using raycast, but I don’t know how.
This is the function I’m using for the gun to shoot with raycast (keep in mind this is a server script inside the gun tool):
function createBullet(player, origin, hitpos)
bullet.Transparency = 0
local distance = (origin - hitpos).Magnitude
local oldCFrame = CFrame.lookAt(origin,hitpos) * CFrame.new(0,0,-distance/2)
bullet.CFrame = oldCFrame
bullet.Size = Vector3.new(0.1,0.1,distance)
bullet.Parent = workspace
spawn(function()
task.wait(0.1)
if bullet.CFrame == oldCFrame then
bullet.Transparency = 1
end
end)
end