I'm making a shotgun and I'm trying to get the bullets to be randomly generated in the direction the player is pointing at. I can get the bullet to go in the direction of the mouse but I cannot manipulate this value and that's where I'm stuck. I'm kind of new to this and I'm not sure where to go from here
Code so far:
local tool = script.Parent
tool.Name = "Shotgun"
local player = game.Players.LocalPlayer
local char = player.Character
local mouse = player:GetMouse()
----------------------------------------------
function GetBullet()
local p = Instance.new("Part", workspace)
p.FormFactor = "Custom"
p.Size = Vector3.new(1, 1, 1)
p.BrickColor = BrickColor.Black()
p.Reflectance = 0.5
p.CanCollide = false
Instance.new("BodyVelocity", p)
return p
end
local function onEquip()
end
local function onActivate()
local bullet = GetBullet()
local target = mouse.hit
bullet.CFrame = char.Shotgun.Barrel.CFrame
bullet.CFrame = CFrame.new(bullet.Position, target.p) --this is where im stuck
bullet.BodyVelocity.Velocity = bullet.CFrame.lookVector * 50
end
tool.Equipped:connect(onEquip)
tool.Activated:connect(onActivate)

3 comments
use raycasting (easier, phantom forces uses it)
Why he want to random gen bullets of a shotgun?
like when you shoot a shotgun it's a bunch of pellets that are scattered