This is my code:
local mob = require(script.Mob) local map = workspace.Grassland
for wave=1, 5 do
print("WAVE STARTING:", wave)
if wave < 5 then
( this is the line with the problem) mob.Spawn("Zombie", 3 * wave, map)
elseif wave == 5 then
mob.Spawn("Zombie", 100, map)
end
repeat task.wait(1) until #map.Mob:GetChildren() == 0 print("WAVE ENDED") task.wait(1)
end
This is a TD code This is the output error: serverscriptservice.Main:7: attempt to index nil with 'Spawn'
Main=Name of script.
Mob script:
local ServerStorage = game:GetService("ServerStorage") 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 = 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("requsted mob does not exist:", name) end
end
return Mob
The console error:
"serverscriptservice.Main:7: attempt to index nil with 'Spawn'"
would heavily imply that your Main script's definition of your mob script is incorrect. Make sure your Mob script is a direct child of your Main script