How would i check when NPC is killed?

Hello there! :wave:

I’m wondering how I would run something for a player once a NPC got killed by that player. The NPC is basically just like a character that chases you and takes damage when it hits you.

1 Like

Just constantly check if thier Humanoid.Health is 0.

But how would I check if a specific player killed the NPC?

humanoid.Died:Connect(function()

1 Like

Thanks! That might work! (i’ll try it out)

This might be hard, however the best thing I can say is using Touched event on the NPC, so whenever his health is 0, it would save whoever’s Part Touched the humanoid in the argument. Then just use that argument’s parent and find the player with the character model.

1 Like

You’re going to want to look into kill tag systems. You can find an in-depth explanation here.

Once the NPC dies, which can be seen when hooking it to humanoid.Died:Connect(function(), you can check the kill tag and then if the tag and the specific player are the same, you got what you want.

Don’t use .Touched to detect who killed them.

1 Like

In the script where the player does damage to the NPC, check the NPC’s health immediately after the script does the damage, if the NPC’s humanoid’s Health property is less than or equal to 0, then you know that this player killed the NPC.

For example:

if Npc.Humanoid.Health <= 0 then
    -- Reward player and stuff
end
3 Likes