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:
1 | Humanoid.Died:Connect( function () |
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:
02 | local NPCFolder = game.Workspace.NPCFolder |
03 | local NPC = game.ReplicatedStorage.Zombie |
08 | if #NPCFolder:GetChildren() < ( MaxZombies + 1 ) then |
09 | local NewNPC = NPC:Clone() |
10 | NewNPC.Parent = game.Workspace.NPCFolder |
11 | NewNPC.Position = Spawner.Position + Vector 3. new( 0 , 4 , 0 ) |
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:
02 | local Humanoid = script.Parent:FindFirstChild( "Humanoid" ) |
03 | local NPC = game.ReplicatedStorage.Zombie |
04 | local Spawner = game.Workspace.Spawner |
07 | Humanoid.Died:Connect( function () |
08 | local NewNPC = NPC:Clone() |
09 | NewNPC.Parent = game.Workspace |
10 | NewNPC.Position = Spawner.Position + Vector 3. new( 0 , 4 , 0 ) |
More On Humanoid.Died
I hope this Helps!