I am making a tower defense game with the help of a tutorial, it is old and surely does not work that well anymore, I made these two codes, a module one inside of a normal one:
Main:
`local mob = require(script.Mob)
local map = workspace.Forest
for wave=1, 5 do
print("WAVE " .. wave .. " STARTING")
if wave < 5 then
mob.Spawn("Zombie", 3 * wave, map)
elseif wave == 5 then
mob.Spawn("Zombie", 20 * wave, map)
end
repeat
task.wait(1)
until #map.Mob:GetChildren() == 0
print("WAVE ENDED")
task.wait(1)
end`
Module:
`local mob = {}
function mob.Move(mob, map)
local humanoid = mob:WaitForChild("Humanoid")
local waypoints = map.Waypoints
for waypoint=1, #waypoints:GetChildren() do
humanoid:MoveTo(waypoints[waypoint].Position)
humanoid.MoveToFinished:Wait()
end
mob:Destroy()
end
function mob.Spawn(name, quantity, map)
local mobExists = game.ServerStorage.Mobs:FindFirstChild(name)
if mobExists then
for i = 1, quantity do
task.wait(0.5)
local newMob = mobExists:Clone()
newMob.HumanoidRootPart.CFrame = map.Start.CFrame
newMob.Parent = map.Mob
coroutine.wrap(mob.Move)(newMob, map)
end
else
warn("Requested mob does not exist", name)
end
end
return mob`