Guessing it must be a return statement somewhere in your code. It’s weird though, roblox code editor should tell if a line can’t be reached, so maybe it’s something else – something like an infinite loop maybe?
Try this:
local PlrName = script.Parent.Name
local Plr = game.Workspace:FindFirstChild(PlrName)
if Plr then
local Humanoid = Plr:FindFirstChild("Humanoid")
Humanoid.Died:Connect(function()
if Humanoid then
print("Dead")
end
end)
end
this should work
How can error check for a humanoid if it’s gone/dead …
Just take out the: if humanoid then … It would not have fired unless they died.
No need for the error check. In this case the error check is the error.
The humanoid instance will still be there for some time upon dying, so it is not the problem at all.
I understand that … but that time is not set in stone. If this isn’t working then humanoid is not set up right.
I think the issue, in truth, is that the script simply isn’t firing that part of the code at all. I have decided to handle the death using a separate script, which works just fine.
You just gave us a snippet with no real context … in a perfect world that snippet is correct.
I found two posts (here and here) saying that .Died won’t fire if the NPC loses all its health in one go. It needs to take damage at least one other time before the fatal blow for .Died to work. If all else fails, then you may be able to do Humanoid:GetPropertyChangedSignal("Health")
.
local HealthHitZero = false
script.Parent.Humanoid:GetPropertyChangedSignal("Health"):Connect(function()
if HealthHitZero then return end
local Value = script.Parent.Humanoid.Health
if Value <= 0 then
HealthHitZero = true
--// Put code for responding to death here
end
end)
If your script and everything work as intended without any flaw, Humanoid.Died should still fire upon instant death. You can try by setting the health immediately to 0 or do TakeDamage(math.inf)
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.