So i have been making a spawning zombies wave system for the past hours. And im getting an issues which frustrate me.
Issues: ServerScriptService.Waves:80: missing argument #1 to ‘wrap’ (function expected). I will highlight which line is that. (This is a module script)
Yet if i remove the coroutine.wrap in the Move function it wont spawn more than 1 zombies, they’re stuck but doesn’t yield any error
local enemies = game:GetService("ReplicatedStorage").Enemies
local wave = {}
wave.Wave = 0
function wave:Move(enemy)
local enemy = enemy
local zombietorso = enemy:WaitForChild("Torso")
local zombiehumanoid = enemy:WaitForChild("Humanoid")
local enemyAnimation = enemy:WaitForChild("Animations")
local function findtarget()
local agrodistance = math.huge
local target = nil
for i, v in pairs(game.Workspace.Unit:GetChildren()) do
local human = v:FindFirstChild("Humanoid")
local torso = v:FindFirstChild("Torso")
if human and torso and v ~= script.Parent then
if (zombietorso.Position - torso.Position).magnitude < agrodistance then
agrodistance = (zombietorso.Position - torso.Position).magnitude
target = torso
end
end
end
return target
end
coroutine.wrap(function()
while task.wait() do
local torso = findtarget()
if torso then
zombiehumanoid:MoveTo(torso.Position)
else
zombiehumanoid:MoveTo(workspace.Goal.Position)
end
end
end)()
end
function wave:Create(data)
wave.Wave += 1
local endedEvent = Instance.new("BindableEvent")
local waveEnemies = Instance.new("Folder")
waveEnemies.Name = tostring(wave.Wave)
waveEnemies.Parent = workspace.Enemies
waveEnemies.ChildRemoved:Connect(function()
if #waveEnemies:GetChildren() == 0 then
endedEvent:Fire()
end
end)
endedEvent.Event:Connect(function()
waveEnemies:Destroy()
end)
for enemyType, amount in pairs(data) do
local enemy = enemies:FindFirstChild(enemyType)
for i = 1, amount do
task.wait(1)
local clone = enemy:Clone()
clone:SetPrimaryPartCFrame(CFrame.new(math.random(18,50), 2.115, 13.249))
clone.Parent = waveEnemies
coroutine.wrap(wave:Move(clone))() -- This Line
end
end
local currentWave = {Ended = endedEvent.Event}
function currentWave:End()
endedEvent:Fire()
end
return currentWave
end
return wave