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

Only 5 mobs spawn in total in one wave, more should spawn. why isn't the code in my script working?

Asked by 2 years ago
Edited by appxritixn 2 years ago
local mob = require(script.Mob)
local map = workspace.Grassland

for wave=1, 5 do

    print("WAVE STARTING:", wave)
    if wave < 5 then 
        mob.Spawn("Zombie", 3 * wave, map)
    elseif wave == 5 then
        mob.Spawn("Zombie", 100, map)
    end
    print("WAVE ENDED")
    task.wait(1)
end 

Here is my coding for spawning the monsters:

local ServerStorage = game:GetService("ServerStorage")
local mob = {}


function mob.Move(mob, map)
    local humanoid = mob:WaitForChild("Humanoid")
    local waypoints = game.Workspace.WayPoints

    for waypoint=1, #waypoints:GetChildren() do
        humanoid:MoveTo(waypoints[waypoint].Position)
        humanoid.MoveToFinished:Wait()
    end
    mob:Destroy()
end

function mob.Spawn(name, map)
    local mobExists = ServerStorage.Mobs:FindFirstChild(name)

    if mobExists then
            local newMob = mobExists:Clone()
            newMob.HumanoidRootPart.CFrame = game.Workspace.Start.CFrame
            newMob.Parent = workspace
            coroutine.wrap(mob.Move)(newMob, map)
    else
        warn("requested mob does not exist:", name)
    end
end

return mob
0
There seem to be inconsistencies in your code. In your first code snippet, mob.Spawn has 3 arguments, whereas in the second code snippet it has 2. appxritixn 2235 — 2y

1 answer

Log in to vote
0
Answered by 2 years ago

It seems in your first code mob.Spawn has 3 arguments but in the module script you have no argument to define that. I believe that the 2nd argument would be how many mobs are spawning. In that case, I would say a code that might work would be this:

function mob.Spawn(name, count, map)
    local mobExists = ServerStorage.Mobs:FindFirstChild(name)

    if mobExists then
    for i=1,count do
                local newMob = mobExists:Clone()
                newMob.HumanoidRootPart.CFrame = game.Workspace.Start.CFrame
                newMob.Parent = workspace
                coroutine.wrap(mob.Move)(newMob, map)
        else
            warn("requested mob does not exist:", name)
        end 
    end
end
Ad

Answer this question