Detecting if player hit humanoid

I’ve been working on my game (as always…) and I was scripting a NPC that fights back when their health changes…

Since I am an absolute goof, I was too lazy to even TRY and code anything else.

I have a problem, though.

There are other enemies that attack and will lead to the NPC attacking innocent players.

Is there any way to detect if a player has hit an NPC? or is that just straight up impossible.

1 Like

Yup, you can do that in your weapon’s code (or whatever the player can use to take damage). You can use a BindableEvent for example to execute code on damage.

1 Like

Yes there are multiple ways. You could keep the NPC’s in a folder and check it’s parent for hits. You could use SetAttribute() to things you want to hit. Or my personal preference is CollectionService to collect groups of targets together. Using CollectionService the objects are uniquely added to a table and allow iteration, and management much easier if you have multiple NPC types.


This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.