I used .Died to detect when I kill an AI but it isn't working?
if game.Workspace.Enemies.Dark5.Zombie.Died == true then
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.
This discussion is preserved as it was. New answers, comments, and votes are closed.
8 comments
He does not know for loops but nice tutorial man, upvoted.
Thanks, right back at you
that didn't work, idk if I'm doing something wrong, the error said that there was something wrong with the ends
You must of changed something. I just put everything in studio and no errors pop up.
when I put it into studio it underlines the } on line 12 in red?
nvm
hang on, I'm a little lost, I think you thought that Zombie was the enemy, Dark5 is the enemy and Zombie is the humanoid, I tried to fix this but am not a great scripter, I don't really get the in pairs part
The for part essentially sais "for everything thing in Enemies i wil be the position index and zombie will be the object itself so..."