Currently, I'm working on a shotgun, and right now it only fires one bullet at a time, as if it were a semi-auto rifle or pistol. However, I want it to fire like a shotgun. How can I do so? Here is the script for how I make the shotgun fire bullets (I am using RayCasting by the way):
Script:
if ammo.Value > 0 and not reloading then
sparkGui.Enabled = true
for i = 1, 8 do
local randomValue1 = math.random(-spread.Value, spread.Value)
local randomValue2 = math.random(-spread.Value, spread.Value)
local ray = Ray.new(flare.CFrame.p, (mouse.hit.p - flare.CFrame.p).unit * range.Value)
local touch, position = workspace:FindPartOnRay(ray, player.Character)
if touch then
OnHit:FireServer(touch)
end
if allowTracing.Value then
local bullet = Instance.new("Part")
bullet.Anchored = bullet
bullet.CanCollide = false
bullet.Transparency = 0.8
bullet.BrickColor = BrickColor.White()
bullet.Material = Enum.Material.SmoothPlastic
local distance = (flare.CFrame.p - position).magnitude
bullet.Size = Vector3.new(0, 0, distance)
bullet.CFrame = CFrame.new(flare.CFrame.p, position) * CFrame.new(0, 0, -distance/2)
bullet.Parent = workspace
game:GetService("Debris"):AddItem(bullet, 0.1)
end
end

4 comments
You need to create the bullets, freeze them, then make them fire.
after all 8 are created.
I did that, but it still fires like one bullet
I want it to spread, like a shotgun would