✓ Accepted answer
Hello,
If the script above by "imnotaguest1121" did not work then try out my idea!
Connect Function When NPC Dies
Make a spawner anywhere in the map wherever you want and make the Zombie NPC and parent it to ReplicatedStorage. Make a script in the Zombie that connects a function() to an Humanoid.Died Event when zombie dies, you can obtain that by:
Humanoid.Died:Connect(function()
end)
When the humanoid dies what you can do is Clone() the Zombie from ReplicatedStorage and set the position of the zombie to the spawner's Position. After about 2 - 5 seconds after the Zombie death you can :Destroy the Zombie.
Specific Amount Of NPC's
If you want a specific amount of Zombies, lets say about 5 then you can put the new cloned NPC's in a NPC folder and then count the children and add one if there is not enough Zombies, this will be obtained by:
local NPCFolder = game.Workspace.NPCFolder
local NPC = game.ReplicatedStorage.Zombie
local MaxZombies = 5
while wait(0.5) do
if #NPCFolder:GetChildren() < ( MaxZombies + 1 ) then
local NewNPC = NPC:Clone()
NewNPC.Parent = game.Workspace.NPCFolder
NewNPC.Position = Spawner.Position + Vector3.new(0,4,0)
end
end
Spawn a NPC after the Old NPC's Death
if you want one or more Zombies but they spawn after the Zombies in Workspace die
what you can do is:
local Humanoid = script.Parent:FindFirstChild("Humanoid")
local NPC = game.ReplicatedStorage.Zombie
local Spawner = game.Workspace.Spawner
Humanoid.Died:Connect(function()
local NewNPC = NPC:Clone()
NewNPC.Parent = game.Workspace
NewNPC.Position = Spawner.Position + Vector3.new(0,4,0)
wait(3)
script.Parent:Destroy
end)
More On Humanoid.Died
I hope this Helps!
2 comments
Omg tysm! I never thought of using humanoid.died!
your welcome, I am very Impressed from how fast you replied!, this is my first answer so i am thankful that it helped!