How to Detect Player who Killed NPC

I was wondering how do I make an NPC detect which player killed him using a power (not a tool power) I thought of saving the player’s nick in an attribute and in the npc script checking the attribute value but it didn’t work and I would like to to know how you would make this system, i tried to dig deep but i only found this type of system used in a sword in a tool. (I don’t want a ready-made script, I just want to know the method you would use)

1 Like

There are a couple of aproaches to this problem. One being that you actually have the player using the power determine which NPC he is targeting and relaying such data onto the NPC. Other methods I have in mind requiring me knowing how this “Power” kills the NPC though, so could you provide that for me please?

maybe use when player deal damage like :TakeDamage() then in below line do if health <= 0 then it make new instance like Instance.new(“ObjectValue”) and it parent to the NPC and the ObjectValue set to player attacker instance, then the npc handler when died it check who is in the ObjectValue

I use the event played to know when the part played on the npc. For damage I use Hit.Parent.Humanoid:TakeDamage(25)

2 Likes

Usually what I do in my code is I “tag” the npc. Normally when you damage an npc, there would be a remote event that tells the server to swing a sword, which will also give the players name. Then you can “tag” the npc using an attribute or stringvalue. Whenever the npc dies, you can just get the tag and apply whatever you want to game.Players[playername.Value].