How do I make it spawn multiple zombies at a time instead of just one?

When I tried to make it spawn multiple zombies, it spawns them after one is done with the path it has. Script

local Zombie = game.ReplicatedStorage.Enemies.Zombie
local Part1 = game.Workspace.Part1
local Part2= game.Workspace.Part2
local Part3 = game.Workspace.Part3
local Part4 = game.Workspace.Part4
local dead = false
function wave()
	local ZombieClone = Zombie:Clone()
	ZombieClone:SetPrimaryPartCFrame(CFrame.new(-108.33, 0.5, -27.21))
	ZombieClone.Parent = workspace
	wait(1)
	ZombieClone.Humanoid:MoveTo(Part1.Position)
	wait(6)
	ZombieClone.Humanoid:MoveTo(Part2.Position)
	wait(6)
	ZombieClone.Humanoid:MoveTo(Part3.Position)
	wait(6)
	ZombieClone.Humanoid:MoveTo(Part4.Position)
	wait(6)
end
wave()
1 Like

What you can do is add a new thread with a spawn(function() inside the wave function.
This will make it so the function doeesnt yeild

You could also do spawn(function()
wave()
end)
doing this in quick succession can be bad however since you’re starting a new thread

3 Likes

for i=1,15 do
wave()
end

15 being how many zombies you want

An alternate is adding an argument within the wave function that specifies how many zombies are spawning. Using @HiddenKaiser’s method of spawn(function() end) you can achieve this too.

local Zombie = game.ReplicatedStorage.Enemies.Zombie
local Part1 = game.Workspace.Part1
local Part2= game.Workspace.Part2
local Part3 = game.Workspace.Part3
local Part4 = game.Workspace.Part4
local dead = false
function wave(numberOfZombies)
	for index = 1, numberOfZombies do
		spawn(function()
			local ZombieClone = Zombie:Clone()
			ZombieClone:SetPrimaryPartCFrame(CFrame.new(-108.33, 0.5, -27.21))
			ZombieClone.Parent = workspace
			wait(1)
			ZombieClone.Humanoid:MoveTo(Part1.Position)
			wait(6)
			ZombieClone.Humanoid:MoveTo(Part2.Position)
			wait(6)
			ZombieClone.Humanoid:MoveTo(Part3.Position)
			wait(6)
			ZombieClone.Humanoid:MoveTo(Part4.Position)
			wait(6)
		end)
		wait(.25) -- Delay Inbetween Spawning Zombies (Remove if you want)
	end
end
wave(15) --Spawns 15 Zombies
3 Likes

if I were to add more types of zombies, would I do

local Zombie = game.ReplicatedStorage.Enemies.Zombie
local FastZombie = game.ReplicatedStorage.Enemies["Fast Zombie"]
local Part1 = game.Workspace.Part1
local Part2= game.Workspace.Part2
local Part3 = game.Workspace.Part3
local Part4 = game.Workspace.Part4
local dead = false
function wave(numberOfZombies)
	for index = 1, numberOfZombies do
		spawn(function()
			local ZombieClone = Zombie:Clone()
			ZombieClone:SetPrimaryPartCFrame(CFrame.new(-108.33, 0.5, -27.21))
			ZombieClone.Parent = workspace
			wait(1)
			ZombieClone.Humanoid:MoveTo(Part1.Position)
			wait(6)
			ZombieClone.Humanoid:MoveTo(Part2.Position)
			wait(6)
			ZombieClone.Humanoid:MoveTo(Part3.Position)
			wait(6)
			ZombieClone.Humanoid:MoveTo(Part4.Position)
			wait(6)
		end)
		wait(1) -- Delay Inbetween Spawning Zombies (Remove if you want)
	end
	 spawn(function()
		local FastZombieClone = FastZombie:Clone()
			FastZombieClone:SetPrimaryPartCFrame(CFrame.new(-108.33, 0.5, -27.21))
			FastZombieClone.Parent = workspace
			wait(1)
			FastZombieClone.Humanoid:MoveTo(Part1.Position)
			wait(3)
			FastZombieClone.Humanoid:MoveTo(Part2.Position)
			wait(3)
			FastZombieClone.Humanoid:MoveTo(Part3.Position)
			wait(3)
			FastZombieClone.Humanoid:MoveTo(Part4.Position)
			wait(3)
	end)
end
wave(5) 

No, to add more zombies all you would do is add to the parameter inside of wave()
so wave(30) would spawn 30 zombies.

1 Like

so like this?

local Zombie = game.ReplicatedStorage.Enemies.Zombie
local FastZombie = game.ReplicatedStorage.Enemies["Fast Zombie"]
local Part1 = game.Workspace.Part1
local Part2= game.Workspace.Part2
local Part3 = game.Workspace.Part3
local Part4 = game.Workspace.Part4
local dead = false
function wave(numberOfZombies)
	for index = 1, numberOfZombies do
		spawn(function()
			local ZombieClone = Zombie:Clone()
			ZombieClone:SetPrimaryPartCFrame(CFrame.new(-108.33, 0.5, -27.21))
			ZombieClone.Parent = workspace
			wait(1)
			ZombieClone.Humanoid:MoveTo(Part1.Position)
			wait(6)
			ZombieClone.Humanoid:MoveTo(Part2.Position)
			wait(6)
			ZombieClone.Humanoid:MoveTo(Part3.Position)
			wait(6)
			ZombieClone.Humanoid:MoveTo(Part4.Position)
			wait(6)
		end)
		wait(1) -- Delay Inbetween Spawning Zombies (Remove if you want)
		local FastZombieClone = FastZombie:Clone()
			FastZombieClone:SetPrimaryPartCFrame(CFrame.new(-108.33, 0.5, -27.21))
			FastZombieClone.Parent = workspace
			wait(1)
			FastZombieClone.Humanoid:MoveTo(Part1.Position)
			wait(3)
			FastZombieClone.Humanoid:MoveTo(Part2.Position)
			wait(3)
			FastZombieClone.Humanoid:MoveTo(Part3.Position)
			wait(3)
			FastZombieClone.Humanoid:MoveTo(Part4.Position)
			wait(3)
	end
end
wave(5) 

See the wave(15)
The number inside the parenthrases determine the number in his script.

He’s asking if he wanted to spawn another type of zombie

1 Like

You can add another argument into the wave function that specifies what type of zombie you want to spawn.

local Zombie = game.ReplicatedStorage.Enemies.Zombie
local FastZombie = game.ReplicatedStorage.Enemies["Fast Zombie"]
local Part1 = game.Workspace.Part1
local Part2= game.Workspace.Part2
local Part3 = game.Workspace.Part3
local Part4 = game.Workspace.Part4
local dead = false
function wave(zombieType, numberOfZombies)
	for index = 1, numberOfZombies do
		spawn(function()
			local ZombieClone = zombieType:Clone()
			ZombieClone:SetPrimaryPartCFrame(CFrame.new(-108.33, 0.5, -27.21))
			ZombieClone.Parent = workspace
			wait(1)
			ZombieClone.Humanoid:MoveTo(Part1.Position)
			wait(6)
			ZombieClone.Humanoid:MoveTo(Part2.Position)
			wait(6)
			ZombieClone.Humanoid:MoveTo(Part3.Position)
			wait(6)
			ZombieClone.Humanoid:MoveTo(Part4.Position)
			wait(6)
		end)
		wait(.25) -- Delay Inbetween Spawning Zombies (Remove if you want)
	end
end
wave(FastZombie, 30) --Spawns 30 FastZombies
wave(Zombie, 15) --Spawns 15 Zombies
2 Likes

I see didnt realize he said that lol, to acomplish this you can also use randomized selection.

I can’t tell if I am setting this up correctly

local Zombie = game.ReplicatedStorage.Enemies.Zombie
local FastZombie = game.ReplicatedStorage.Enemies["Fast Zombie"]
local Part1 = game.Workspace.Part1
local Part2= game.Workspace.Part2
local Part3 = game.Workspace.Part3
local Part4 = game.Workspace.Part4
local dead = false
function wave(zombieType, numberOfZombies)
	for index = 1, numberOfZombies do
		spawn(function()
			local ZombieClone = Zombie:Clone()
			ZombieClone:SetPrimaryPartCFrame(CFrame.new(-108.33, 0.5, -27.21))
			ZombieClone.Parent = workspace
			wait(1)
			ZombieClone.Humanoid:MoveTo(Part1.Position)
			ZombieClone.Humanoid.MoveToFinished:Wait()
			ZombieClone.Humanoid:MoveTo(Part2.Position)
			ZombieClone.Humanoid.MoveToFinished:Wait()
			ZombieClone.Humanoid:MoveTo(Part3.Position)
			ZombieClone.Humanoid.MoveToFinished:Wait()
			ZombieClone.Humanoid:MoveTo(Part4.Position)
			ZombieClone.Humanoid.MoveToFinished:Wait()
		end)
		wait(1) 
	for index = 2, numberOfZombies do
		local FastZombieClone = FastZombie:Clone()
			FastZombieClone:SetPrimaryPartCFrame(CFrame.new(-108.33, 0.5, -27.21))
			FastZombieClone.Parent = workspace
			wait(1)
			FastZombieClone.Humanoid:MoveTo(Part1.Position)
			FastZombieClone.Humanoid.MoveToFinished:Wait()
			FastZombieClone.Humanoid:MoveTo(Part2.Position)
			FastZombieClone.Humanoid.MoveToFinished:Wait()
			FastZombieClone.Humanoid:MoveTo(Part3.Position)
			FastZombieClone.Humanoid.MoveToFinished:Wait()
			FastZombieClone.Humanoid:MoveTo(Part4.Position)
			FastZombieClone.Humanoid.MoveToFinished:Wait()
	end
end
end
wave(FastZombie, 3) --Spawns 30 FastZombies
wave(Zombie, 3) --Spawns 15 Zombies

Use what I have written out for you. It will spawn the zombiesType and the numberOfZombies when you call the function.

wave(Zombie, 100) -- This spawns 100 Zombies
wave(FastZombie, 30) -- This spawns 30 Zombies

You don’t need to add any more within the function.

2 Likes

Also, final question. Is this a roblox studio problem? I put all the enemies to have can collide off so they don’t bump into each other, but they still do bump into eachother and can collide turns back on.

This is not a studio problem. This is due to the PhysicsService, which creates a collision for all instances that have a humanoid. Your best bet would be to use the PhysicsService Collision to set these instances to false. I can create a function that does this for you.

local physicsService = game:GetService("PhysicsService")
physicsService:CreateCollisionGroup("Zombies")
physicsService:CollisionGroupSetCollidable("Zombies", "Zombies", false)

local Zombie = game.ReplicatedStorage.Enemies.Zombie
local FastZombie = game.ReplicatedStorage.Enemies["Fast Zombie"]
local Part1 = game.Workspace.Part1
local Part2= game.Workspace.Part2
local Part3 = game.Workspace.Part3
local Part4 = game.Workspace.Part4
local dead = false
function wave(zombieType, numberOfZombies)
	for index = 1, numberOfZombies do
		spawn(function()
			local ZombieClone = zombieType:Clone()
			for _, part in ipairs(ZombieClone:GetDescendants()) do
				if part:IsA("BasePart") then
					physicsService:SetPartCollisionGroup(part, "Zombies")
				end
			end
			ZombieClone:SetPrimaryPartCFrame(CFrame.new(-108.33, 0.5, -27.21))
			ZombieClone.Parent = workspace
			wait(1)
			ZombieClone.Humanoid:MoveTo(Part1.Position)
			wait(6)
			ZombieClone.Humanoid:MoveTo(Part2.Position)
			wait(6)
			ZombieClone.Humanoid:MoveTo(Part3.Position)
			wait(6)
			ZombieClone.Humanoid:MoveTo(Part4.Position)
			wait(6)
		end)
		wait(.25) -- Delay Inbetween Spawning Zombies (Remove if you want)
	end
end
wave(FastZombie, 30) --Spawns 30 FastZombies
wave(Zombie, 15) --Spawns 15 Zombies
2 Likes