This script spawns a random zombie from a folder on to a random block. But doen't respawn them.
I can't make it so that when of the created zombies dies it makes the number value go down, which in turn will spawn a replacement zombie. .
local NPCS = game.ReplicatedStorage.Enemies:GetChildren()
local number = 0
local max = 6
if number <= max then
canspawn = true
print("can spawn")
end
while canspawn do
local ChosenNPC = NPCS[math.random(1, #NPCS)]
local ChosenSpawn = math.random(1, 6)
print(ChosenNPC)
print(ChosenSpawn)
wait(4)
if ChosenNPC then
clone = ChosenNPC:Clone()
clone.HumanoidRootPart.Position = workspace.EnemySpawns:FindFirstChild("Spawn"..ChosenSpawn).Position
clone.Parent = workspace.EnemySpawns.Spawned
clone:MakeJoints()
number = number + 1
print(number)
if clone.Humanoid.Health <= 0 then
number = number -1
print(number)
end
if number >= max then
canspawn = false
print("Stoping spawning")
end
end
end

2 comments
Thanks but, Now they don't spawn at all
Ok I got it working thank you, it was just the folder name was named differently.