Issue with Humanoid.Died

I’m working on a script for my game. It basically handles all the humanoids of the allies of the boss, so when the allies die, they get destroyed.

The issue is that, when i defeat the ally (that i previously cloned onto a special folder inside the workspace), nothing happens.

I have searched for solutions on the dev hub about Humanoid.Died, and changed the script multiple times, but nothing.

local bossstuff = game.ServerStorage.BossStuff

for i,ally in pairs(bossstuff.Allies:GetChildren()) do
	print("model found: "..ally.Name)
	ally.Humanoid.Died:Connect(function()
		ally.AllyScript:Destroy()
		ally.HumanoidRootPart.Damage:Destroy()
		wait(2.5)
		ally:Destroy()
	end)
end

Output contains what i expected: model found: Noob. No errors.
Script is on ServerScriptService. Here is the BossStuff folder hierarchy:
image

1 Like

Couldn’t you just reference a ChildAdded event to detect when that specific Ally gets destroyed inside the Folder? I believe only the first Noob NPC (If that) would only get detected, even still you could just detect whenever a NPC gets added with using a ChildAdded event so that it easily keeps track of all the individual allies:

local AllyFolder = workspace.AllyFolder

AllyFolder.ChildAdded:Connect(function(Ally)

    if Ally:IsA("Model") and Ally.Name == "Noob" then --Checking if the Ally is an actual NPC/Model object
        Ally.Humanoid.Died:Connect(function()
		    Ally.AllyScript:Destroy()
		    Ally.HumanoidRootPart.Damage:Destroy()
		    wait(2.5)
		    Ally:Destroy()
        end)
    end
end)

Edit: W h o o p s I only just copy/pasted a scrap of the code, didn’t see that thanks

I’m gonna ChildAdded then, unluckily ALL the boss stuff (allies, bullets and such) are inside a same folder, that its contents will get deleted when the boss dies, anyways tho, thanks that the allies have a script with a specific name, i could find them.

Also be a bit more careful with your uppercase and lowercase letters pal :wink: you forgot to change some ally to Ally

1 Like

Worked perfectly, tysm :upside_down_face:

Had to do some minor edits due to the things i said earlier, but thanks for telling me to use ChildAdded. If you know why my original script didnt worked, could you reply me please so i know what to do in the future?

1 Like

Well, assuming from the script you first posted

bossstuff.Allies:GetChildren() would only save what would exactly be in that “Allies” Folder, so it’d only return back the table with 1 Ally inside it (Or the Noob inside the Folder)

I don’t believe that Events can connect with cloning new Models if there’s already a connection being established with the original Model, but I’m unsure as to why this is

I suppose what you could do in the future is just use ChildAdded for the time being, or when you first start to clone the Model you can detect when its Humanoid dies so you can keep track of its entire Clone in 1 script

1 Like

Ok, ill put that in practice whenever i need to. Thanks for your time!

1 Like