If you want them to respawn, you have to find a way to detect how many zombies there are left.
local ZombiesLeft = 0
Now, you have to create a NumberValue and put it in the script.
local ZLeftNV = Instance.new('NumberValue')
ZLeftNV.Parent = script
You have to create a function to spawn the zombies, and add 1 to ZombiesLeft after one spawns in.
local limit = 3
function spawnZombies()
zombieCheck()
for i = 1,limit do
wait(5)
ZombiesLeft = ZombiesLeft + 1
ZLeftNV.Value = ZLeftNV.Value + 1
local newzombie = zombiebackup:Clone()
newzombie.Parent = game.Workspace
newzombie:MakeJoints()
newzombie.Torso.CFrame = script.Parent.CFrame + Vector3.new(0, 5, 0)
newzombie:MakeJoints()
zombie = newzombie
zombiebackup = zombie:Clone()
end
end
function zombieCheck()
if ZombiesLeft == 0 then
spawnZombies()
end
end
zombieCheck()
ZLeftNV.Changed:connect(function()
ZombiesLeft = ZLeftNV.Value
end)
Now inside the Zombie model, every time one dies, you have to decrease the ZLeftNV by 1.
Humanoid = script.Parent.Humanoid
Humanoid.Died:connect(function()
workspace.Script.ZLeftNV.Value = workspace.Script.ZLeftNV.Value - 1
end)