I’ve made a gun which shoots bullets which have bodyvelocity in them as the force making them go forward but I’m not sure how to make spread for them as if I try to like add force to the left or right for spread the bullets just don’t go forward but sideways
function Fire(MousePos, MouseCFrame)
local BarrelPos = Barrel.Position
local LastStep = BarrelPos
for i = 1,6 do
local Bullet = game.ReplicatedStorage.Bullet:Clone()
Bullet.CFrame = CFrame.new(BarrelPos, ReturnPosFromRay(MousePos)) * CFrame.new(0, 0, -2);
local bv = Instance.new("BodyVelocity", Bullet)
bv.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
bv.Velocity = MouseCFrame.LookVector * 30;
Effects:FireServer(Barrel,RayColor)
if FireSound then
SoundEvent:FireServer(FireSound)
end
Bullet.Parent = game.Workspace.BulletStorage
local ray = Ray.new(Handle.CFrame.p,(Player:GetMouse().Hit.p - Handle.CFrame.p).unit*300)
local part,position = game.Workspace:FindPartOnRayWithIgnoreList(ray,IgnoreTable)
if part then
local distance = (game.Players.LocalPlayer.Character.HumanoidRootPart.Position - part.Position).magnitude
local OtherPlayer = game.Players:GetPlayerFromCharacter(Humanoid.Parent)
if TKEnabled or (OtherPlayer and OtherPlayer.TeamColor ~= Player.TeamColor or Player.Neutral) or not OtherPlayer then
if distance <= 20 and distance <=49 then
DamageEvent:FireServer(Humanoid, BaseDamage)
elseif distance >= 50 and distance <=99 then
DamageEvent:FireServer(Humanoid, BaseDamage/1.2)
print(BaseDamage/1.2)
elseif distance >= 100 and distance <=119 then
DamageEvent:FireServer(Humanoid, BaseDamage/2.5)
print(BaseDamage/2.5)
elseif distance >= 120 and distance <=139 then
DamageEvent:FireServer(Humanoid, BaseDamage/3)
print(BaseDamage/3)
elseif distance >= 140 and distance <=199 then
DamageEvent:FireServer(Humanoid, BaseDamage/6)
print(BaseDamage/6)
elseif distance >= 200 and distance <=250 then
DamageEvent:FireServer(Humanoid, BaseDamage/12)
print(BaseDamage/12)
else
DamageEvent:FireServer(Humanoid, BaseDamage/15)
print(BaseDamage/15)
end
end
end
delay(1, function()
Bullet:Destroy()
end)
end
end