So i have a code that opens a door when 1 npc dies but i need it to only open when 2 or more certain npcs die. So for example, when 1 npc dies the door stays closed, but when the other one dies the door opens.
function door() local open = script.Parent.Health local doorr = game.Workspace.part3 if open <1 then doorr.Transparency = 0.5 doorr.CanCollide = false end end script.Parent.Died:Connect(door)
I put this in the npc's humanoid
Try this:
local npc1 = workspace.NPC1 -- Change NPC1 to the name of your npc local npc2 = workspace.NPC2 -- Change NPC2 to the name of your npc local door = workspace.part3 local died = 0 npc1.Humanoid.Died:Connect(function() died = died + 1 end) npc2.Humanoid.Died:Connect(function() died = died + 1 end) coroutine.wrap(function() while wait() do if died == 2 then door.Transparency = 0.5 door.CanCollide = false break end end end)()
Whenever an NPC dies, the died value gets increased. Then the while loop inside the coroutine constantly checks if the died value is equal to 2. If it is, the door opens and the while loop breaks. Make the script a regular/server script inside Workspace
or ServerScriptService
.