Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Yo, i need help with enemys not spawing? (Read Discription)(TD)

Asked by 1 year ago
Edited 1 year ago

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

0
Show us your "mob" script virushunter9 943 — 1y
0
RIP format LikeableEmmec 470 — 1y
0
Also, that is probably the greatest name on Roblox. LikeableEmmec 470 — 1y

1 answer

Log in to vote
1
Answered by 1 year ago

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

Ad

Answer this question