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()
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
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)
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
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
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