I'm trying to work out a Zombie wave script, however, the function keeps repeating only wave one. I'm trying to make it so that once all Zombies are killed, it moves onto the next wave. I only about a week into learning Lua so I'm a huge newbie.
local tZombie = game:GetService("ServerStorage").Zombie1
local zCnt = 0
local rnd = Random.new()
print("Spawning Wave 1")
local function spawnZombies()
for i= -1118, 8, 230 do
local zombie = tZombie:Clone()
zombie.Parent = workspace.Zombies
local xLoc = rnd:NextInteger(-75,10)
local zLoc = rnd:NextInteger(-75,10)
local pos = Vector3.new(xLoc, 3, zLoc)
zombie:MoveTo(pos)
end
end
local function getZCount()
local num = #workspace.Zombies:GetChildren()
return num
end
while true do
if zCnt <20 then
print("Spawning Zombies Wave 1")
spawnZombies()
end
zCnt = getZCount()
wait(5)
end
print("Spawning Wave 2")
local function spawnZombies()
for i= -1118, 8, 230 do
local zombie = tZombie:Clone()
zombie.Parent = workspace.Zombies
local xLoc = rnd:NextInteger(-75,10)
local zLoc = rnd:NextInteger(-75,10)
local pos = Vector3.new(xLoc, 3, zLoc)
zombie:MoveTo(pos)
end
end
local function getZCount()
local num = #workspace.Zombies:GetChildren()
return num
end
while true do
if zCnt <30 then
print("Spawning Zombies Wave 2")
spawnZombies()
end
zCnt = getZCount()
wait(5)
end
print("Spawning Wave 3")
local function spawnZombies()
for i= -1118, 8, 230 do
local zombie = tZombie:Clone()
zombie.Parent = workspace.Zombies
local xLoc = rnd:NextInteger(-75,10)
local zLoc = rnd:NextInteger(-75,10)
local pos = Vector3.new(xLoc, 3, zLoc)
zombie:MoveTo(pos)
end
end
local function getZCount()
local num = #workspace.Zombies:GetChildren()
return num
end
while true do
if zCnt <40 then
print("Spawning Zombies Wave 3")
spawnZombies()
end
zCnt = getZCount()
wait(5)
end

1 comment
Try using a repeat loop on spawning the zombies