Spawning function doesnt seem to work

I have a spawn function that should get all the children inside a folder, get the spawners for zombies and then check if the amount of zombies inside the folder is less than a specific value. If it is lower than xyz it will spawn more until it reaches xyz then the function breaks

local function Handler.SpawnZombies()

	local CanSpawnZombies = script.CanSpawnZombies

	while true do

		for number, ZombieSpawners in pairs(workspace.Map.Model.Spawners:GetChildren()) do

			for SpawnedZombies in pairs(workspace.Map.Zombies:GetChildren()) do

				if ZombieSpawners.Name == "spawner" then

					if CanSpawnZombies.Value == true then

						print(SpawnedZombies)

						if SpawnedZombies < zombiesAlive.Value or SpawnedZombies == nil then

							local zombie = game.ServerStorage.Zombies[currmap.Value][currmap.Value.." Zombie"]:Clone()

							zombie.Parent = workspace.Map.Zombies
							zombie.CFrame.Position = math.random(#ZombieSpawners.CFrame.Position)

							workspace.Map.Zombies.ChildAdded:Connect(function(d) -- if a zombie is added add one	
								SpawnedZombies += 1 	
							end)

							if SpawnedZombies == zombiesAlive.Value then

								CanSpawnZombies.Value = false

								break 

							end

						end

					end

				end

			end

		end

		task.wait()
	end

end

Here is the tree for more understanding
image

there’s absolutely no reason for you to add a childadded listener even though you know a child will definitely be added?? furthermore it’s also a logical error as you are not disconnecting it which will cause the increment to not be 1 once the loop iterates again.

its to check if a zombie was added or not, As we use the loop to check if there is any zombies and if not we then add them and we listen to make sure it s added to the folder (AKA being spawned)

not necessary and even more unnecessary doing it every iteration.