So, this question arose by curiosity from another person's question I was trying to answer. I have a lot of enemy npcs in a folder, and i want a gate to open when all of them have died. Here is what I have so far, Any help is appreciated!
local part1 = game.Workspace.Part1
local part2 = game.Workspace.Part2
local t = 0
local npcf = game.Workspace.NPCF:GetChildren() -- npcf is the folder and I am getting all the npcs using GetChildren()
local TweenService = game:GetService("TweenService") -- these are the tweens which should play if it has died.
local part1 = game.Workspace.Part1
local goal = {}
goal.Position = Vector3.new(-6.197, 22.353, -67.553)
local tweenInfo = TweenInfo.new(5)
local tween1 = TweenService:Create(part1, tweenInfo, goal)
local TweenService = game:GetService("TweenService")
local part2 = game.Workspace.Part2
local goal = {}
goal.Position = Vector3.new(-23.852, 21.838, -66.892)
local tweenInfo = TweenInfo.new(5)
local tween2 = TweenService:Create(part2, tweenInfo, goal)
local npc2 = game.Workspace.NPC2
while true do
for i = 1,#npcf do -- I have no clue what to do for multiple npcs and how to constantly check if ALL OF THEM HAVE DIED
local npcnum = npcf[i]
if npcnum.Humanoid.Health == 0 then
print("npc"..i.."died")
end
end
if npc2.Humanoid.Health == 0 then -- this one works, but its for only1 npc cuz it only checks constantly if 1 npc has died
tween2:play()
end
wait()
end

8 comments
Hi I also tried to do for 1,v in pairs() do but how do I make sure all the different npcs have died using this?
i*
I'm not sure what you mean by different NPCs, could you explain further?
so I have a folder of npc and I want the gate to open when all of them have died, but how do I do that?
Sorry for the late response, was asleep. We're using GetChildren() to get all the npcs inside the folder, then looping through all of them to check if their health is 0.
I know that, but that still doesnt make the script realise whether ALL the npc's have died.
I dont want it to just open when 1 npc has died, i want it to open when all of them have died. how do I know that?
Oh, I thought NPCF was a folder, anyway, make a folder, put in all the NPCS there and use :GetChildren() on the folder.