The title explains it all: How can I detect if a group of NPCs have all died?. I am making a wave based game and it spawns in wave1 but before spawning the wave2 I want it to check if every NPC in wave1 has died. If yes, then spawn wave2 and also do other things.
Here is my script which needs to be modified:
local event = game.ReplicatedStorage.Event
local Waves = game.ServerStorage.Waves
local function onEvent()
wait (5)
local Wave1 = Waves.Wave1:clone()
Wave1.Parent = workspace
local Wave2 = Waves.Wave2:clone()
Wave2.Parent = workspace
local Wave3 = Waves.Wave3:clone()
Wave3.Parent = workspace
local Wave4 = Waves.Wave4:clone()
Wave4.Parent = workspace
local Wave5 = Waves.Wave5:clone()
Wave5.Parent = workspace
local Wave6 = Waves.Wave6:clone()
Wave6.Parent = workspace
local Wave7 = Waves.Wave7:clone()
Wave7.Parent = workspace
local Wave8 = Waves.Wave8:clone()
Wave8.Parent = workspace
local Wave9 = Waves.Wave9:clone()
Wave9.Parent = workspace
local Wave10 = Waves.Wave10:clone()
Wave10.Parent = workspace
end
event.Event:Connect(onEvent)
If the game is round-based, then you can make an IntValue for the amount of NPC’s in the group, and if the Humanoid.Died event occurs, subtract from that amount of NPC’s left. If it equals 0, then whatever you want to happen. Round end, Perk bonus, etc. (Easy)
You can add a table and put all the NPC’s in that group inside of the table, then if the Humanoid.Died event occurs, then remove them from that table. If there is nothing in the table (Check with if MyTableName[1] == nil then), then end the round, give bonus, etc. (Intermediate)
You can ask others for possible solutions I haven’t thought of because this is off of the top of my head. (Easy)
My Game is round based but I want some more information on the first option. I want the other wave to start after ALL zombies in the wave before have been killed. Can I have some more info on the first option.
If there are an infinite amount of zombies, related to games like “Zombie Attack”, and “Zombie Rush”, and you want all the zombies to die if players have killed a certain amount, you can make round based amounts of zombies.
If you want to be specific with the amount of zombies per round, that’s going to take a lot more work,
If you don’t, then simply multiply or add a specific amount of zombies each round.
Lets say our amount of zombies is 5,
If we kill one, the event will fire to check if it equals zero, and if it doesn’t, then don’t end the round.
But if we kill all 5, and the value equals 0, then end the round, give money, increase the amount of zombies x2.
I would prefer to use option #2 as exploiters can easily change the amount of zombies and end the round immediately.
If necessary, would you like some example code to have a basis of what your doing?
Yes and also the way mine works is that it clones a folder from server storage, and then it puts it in workspace, and then I want the first folder deleted after all the zombies in the first folder have died. Also when a zombie dies its body parts still stay on the ground, thats why it deletes that folder when the other round starts. Can you modify my code to do this once, and then I will copy it for the other waves. Do you understand how this works? If yes, then please help me and do the above!