I have a script that spawns a random zombie within a folder onto one of the 6 random blocks within a folder in the workspace. I have it so every time a zombie spawns, the number value is goes up by one.
But how do I get t so when you a zombie dies the number value decreases by one. And in turn will let the while loop keep going and replace the dead zombie?
local NPCS = game.ReplicatedStorage.Enemies:GetChildren()
local number = 0
if number >= 0 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(5)
if ChosenNPC then
clone = ChosenNPC:Clone()
number = number + 1
print(number)
clone.HumanoidRootPart.Position = workspace.EnemySpawns:FindFirstChild("Spawn"..ChosenSpawn).Position
clone.Parent = workspace.EnemySpawns.Spawned
clone:MakeJoints()
if number >= 5 then
canspawn = false
print("Stoping spawning")
end
end
end
