I used .Died
to detect when I kill an AI but it isn't working?
if game.Workspace.Enemies.Dark5.Zombie.Died == true then
As long as there is a humanoid in your Zombie, you actually will want to use the died as shown below. See what happens is when a humanoid dies anything you connect to that died event will trigger and that'show we will listen to when the humanoid dies.
local zombies = {} local function setupZombie(Zombie) local humanoid = Zombie:FindFirstChild("Humanoid") if (not zombies[Zombie]) and humanoid then zombies[Zombie] = {Zombie,humanoid.Died:Connect(function() -- Anything in here will run when the zombie dies -- When it dies make sure to remove it from the table if zombies[Zombie] then zombies[Zombie] [1]:Destroy() -- Destroy automatically will disconnect() zombies[Zombie] = nil -- Set the zombie index to nil so no memory end end)} end end for i,zombie in pairs(game.Workspace.Enemies:GetChildren()) do setupZombie(zombie) -- This will loop every zombie into the function to set it up end
I just woke up to who this may concern, I kind of winged this one.
If this helped you I would greatly appreciate an upvote or solved. Good luck!
Syn above is correct in using died, and the more clunky way is to do health like so:
if script.Parent.Humanoid.Health <= 0 then
But that is slower and usually requires a while loop whereas the :died() connection does not because it listens for the death.