this attack/spell is a shotgun-esk attack in which a barrage of 6 bullets hits an enemy. But it doesn't spread like a normal shotgun. Is there a good way to add spread to my spell?
local Player = game.Players.LocalPlayer local Character = Player.Character or Player.CharacterAdded:wait() local Mouse = Player:GetMouse() Enabled = true Mouse.KeyDown:connect(function(key) if Enabled == false then return end key = key:lower() if key == 'r' then Enabled = false for i=1,6 do --Fire Ball Projectile local FireBall = Instance.new('Part') FireBall.Shape = 'Ball' FireBall.Name = "FireBall" FireBall.Material = 'Neon' FireBall.BrickColor = BrickColor.new('Dark orange') FireBall.Parent = Character.ProjectileStorage FireBall.CFrame = Character.Torso.CFrame*CFrame.new(0,0,-1.5) FireBall.Size = Vector3.new(1,1,1) FireBall.Transparency = 0.1 FireBall.CanCollide = false --Sound Effects local Fire2 = script:WaitForChild('Fire2') local BV = Instance.new('BodyVelocity') BV.MaxForce = Vector3.new(math.huge,math.huge,math.huge) BV.Velocity = Character.Torso.CFrame.lookVector*50 BV.Parent = FireBall local Dmg = script:WaitForChild('FireDamage'):Clone() Dmg.Parent = FireBall Dmg.Disabled = false Fire2:play() --Particles local FireParticle1 = script:WaitForChild('ParticleEmitter'):Clone() FireParticle1.Parent = FireBall FireBall:clone() wait(0.1) --FireBall Destroy local Disapper = script:WaitForChild("Disappear"):Clone() Disapper.Parent = FireBall Disapper.Disabled = false end wait(3) Enabled = true end end)
You would want to add a random factor to the velocity:
local spread = 5 -- Try changing this to suit your needs BV.Velocity = Character.Torso.CFrame.lookVector*50 + Vector3.new( spread*math.random()*2 - spread, spread*math.random()*2 - spread, spread*math.random()*2 - spread) -- Adds -5 to 5 units of velocity on each axis randomly
Also, make sure you initialize your randomizer with proper entropy by placing this at the start or end of the script:
math.randomseed(tick())