How can i find who damaged the Player/NPC

I’m trying to find who killed out a NPC / Player to make a quest system.

SORRY EVERYONE, i got the solution, but thanks all your help!
I: i used ObjectValue to it.

1 Like

Please be more specific. What is being used to damage the Humanoid, did you script this system to damage the Humanoid, how does it work? If you could also include some code examples that would be helpful.

It’s a One Piece game, i need to detect if something damaged the NPC and find the parent of it to receive into a IntValue that’s count as kills, i say something it’s like Devil Fruits Attacks and Combat Systems.

[edit: i have tried any forms to do it but all gone wrong and i deleted it…]

1 Like

Also all the attacks of player it’s parented to HumanoidRootPart of the player who launched it

If you want to find out who killed someone, simply implement it. Could be something as simple as having some sort of object value that changes when the server deals damage to something (from hit detection) by keeping track of who fired the projectile or slashed the character, to making tables to hold this information in the main damage handling script.

Usually, I end up making a wrapper class for my NPCs with properties like WhoKilled which are assigned by the damage script. Essentially, I would create tables to help me interact with the NPC using OOP, where the object representing the NPC is a table that is capable of interacting and controlling the actual physical NPC object ingame. That way I can do:

local guy = NPC.new(NPCType.Base, mapOrigin)
guy:Damage(5000, aPlayer)
if guy:IsDead() then
    print(guy.WhoKilled)
end

But this requires knowing how to work with OOP (which is greatly beneficial in the long run!!!)

Whenever a player damages an NPC, check if the NPC has an ObjectValue called “LastTagged”. If it does not, make a new ObjectValue with the Value property set to the player that damaged the NPC. If the NPC already has an ObjectValue, don’t make a new one! Instead, change the Value property to the player that damaged the NPC. This way when the NPC dies, you can check LastTagged.Value which should be a player object. That player was the last one to hit the NPC and kill them.

This should all be done on the server.

6 Likes