I’ve seen some other posts but didnt get it to work, so if someone could help me add spread to these projectiles i would be very thankful.
local attackmodule = {}
local attacks = require(script.AttackPatternsModule)
local projectiles = game.ServerStorage.Boss.Stuff.Projectiles
local star = projectiles.StarProjectile
local rns = game:GetService("RunService")
function attackmodule.Attack(attack, boss)
if table.find(attacks, attack) ~= nil then
attackmodule.UseAttack(attack, boss)
end
end
function attackmodule.UseAttack(attack, boss)
if attack == "CrystalBarrage" then
print("Boss used Crystal Barrage.")
boss.CanAttack.Value = false
print(boss.CanAttack.Value)
for i=1, math.random(9,12) do
task.wait((math.random(2,3))/15)
local steps = 0
coroutine.wrap(function()
local proj = star:Clone()
proj.Parent = workspace.Debris
proj:MoveTo(boss.PrimaryPart.Position+Vector3.new(math.random(-4, 4),7,math.random(-4, 4)))
local nearestPlayer, nearestDistance
for _, player in pairs(game.Players:GetPlayers()) do
local character = player.Character
local distance = player:DistanceFromCharacter(boss.HumanoidRootPart.Position)
if not character or
(nearestDistance and distance >= nearestDistance)
then
continue
end
nearestDistance = distance
nearestPlayer = player
end
if nearestPlayer ~= nil then
local nhrp = nearestPlayer.Character.HumanoidRootPart
print(CFrame.lookAt(boss.PrimaryPart.Position,nhrp.Position))
proj.PrimaryPart.CFrame = CFrame.lookAt(boss.PrimaryPart.Position,nhrp.Position)
end
local rssteps
rssteps = game:GetService("RunService").Heartbeat:Connect(function()
steps += 1
proj.PrimaryPart.Position = proj.PrimaryPart.Position + proj.PrimaryPart.CFrame.LookVector * 1
if steps >= 150 then
proj:Destroy()
rssteps:Disconnect()
end
end)
return
end)()
end
end
task.wait(0.4)
boss.CanAttack.Value = true
end
return attackmodule