Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

1 comment

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.

1 answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.