I want to making if 4 dummy died then destroy a part
but its not working (its maybe because I don’t learn enough)
I try method: function ded() game.workspace.part:destroy() end game.workspace,dummy.humanoid.died:connect() game.workspace,dummy2.humanoid.died:connect() game.workspace,dummy3.humanoid.died:connect() game.workspace,dummy4.humanoid.died:connect()
its working but when i kill anyone dummy then part will destroy
local num = 0
function Died()
num = num + 1
if num == 4 then
workspace.part:Destroy()
end
end
local Names = {"dummy","dummy2","dummy3","dummy4"}
for _,child in ipairs(workspace:GetChildren()) do
if table.find(Names,child.Name) then
child.Humanoid.Died:Connect(Died)
end
end
Also, please don’t use: LowerCase Destroy, connect, Connect without arguments and , instead of .
Try this, maybe: This just deletes the door if the Dummies are not existing anymore if yes, then its gonna return nil.
local NPCs = {workspace.Dummy, workspace.Dummy2, workspace.Dummy3, workspace.Dummy4}
if NPCs[1] or NPCs[2] or NPCs[3] or NPCs[4] == nil then do
game.workspace.ItsDoor:Destroy()
end
else
return nil
end
Your script doesn’t make any sense, when the Humanoid Dies the npc isn’t deleting itselfs only the event is fired, that will make your code being like this:
if NPCs[1] == true or NPCs[2] == true or NPCs[3] == true or NPCs[4] == nil then do
game.workspace.ItsDoor:Destroy()
end
else
return nil
end
if game.Workspace.Dummy.Humanoid.Health == 0 and
game.Workspace.Dummy2.Humanoid.Health == 0 and
game.Workspace.Dummy3.Humanoid.Health == 0 and
game.Workspace.Dummy4.Humanoid.Health == 0 then
-- Destroy the part
end
local function CreateRoom(Door, Targets)
local count = 0;
for i,v in ipairs(Targets) do
v.Humanoid.Died:Connect(function() count = count + 1; if count == #Targets and Door then Door:Destroy() end end) -- Pretty sure .Died doesn't fire multiple times.
end
end
CreateRoom(workspace.ItsDoor, {workspace.Dummy, workspace.Dummy2, workspace.Dummy3, workspace.Dummy4})
Your code is pretty inneficient and it is doing the same thing like mine but with a bigger wait and inneficient things like wait() without arguments and pairs instead of ipairs. Please check ur code before sending it.