Zombie Spawning Script Support

Hello, I’ve tried my best to look into this script even looking it up on the devforum. But nothing is really helping, what I am trying to achieve is every time a zombie is killed it will clone in replicated storage and then set parent to workspace that way it could be like endless waves. this is what isn’t working its all in one script

– while wait(1)do
local human = script.Parent.Humanoid
human.Died:Connect(function()
local RepStorage = game.ReplicatedStorage
local ZombieClone = RepStorage.Zombie:Clone()
wait(2)
ZombieClone.Parent = game.Workspace
print(“Working all the way”)
end)
end

1 Like

Could you send a video of what is happening and a screenshot of the output?

1 Like

The problem could be that when the Zombie dies, the zombie model get’s destroyed. This script, which is a child of the zombie, would therefore be destroyed before it can run the code to spawn another Zombie. Try adding print statements to see if it makes it to the cloning part.

1 Like

Yes, that’s it. Try moving the script out of the zombie and reference zombie that way. A more advanced way to do this is by having only 1 script and having all zombies in a folder. Then save the number of zombies ti a variable and check when #folder:GetChildren() is less than that number. While it is, clone the zombie.

3 Likes