I made an NPC spawner script that puts a cap on how many zombies can spawn, but I can't figure out how to tell it to spawn more when the cap decreases/a player kills one, it seems to ignore ChildRemoved and stop spawning them even after I cut them from the spawner in Run mode.
local child = game.workspace.Spawn.ChildAdded:Connect(function(child)
end)
local abortion = game.workspace.Spawn.ChildRemoved:Connect(function(abortion)
end)
local ZombieCount = 0
local NPC = game.ReplicatedStorage.Zombie
local spawner = game.workspace.Spawn
while ZombieCount <5 do
local Clone = NPC:Clone()
Clone.Parent = spawner
Clone.Torso.CFrame = spawner.CFrame
wait(1)
if child then ZombieCount = ZombieCount +1
elseif abortion then ZombieCount = ZombieCount -1
end
end
Is there a better method than ChildRemoved or am I just using it wrong?
Is the counter even supposed to be in the while do loop?

2 comments
You're using it wrong. Promise.
Okay, so... What should I use then? Humanoid.Died or something? Or by using it wrong do you mean the function call is wrong...?