How do you play the animation on an enemy when you hit him?

So my goal is to make it so that when you hit an enemy he plays the animation that you hit him. As I understand it, I need to first get a humanoid NPC, and then play there animation. I was told that I should use touched, so when you touch the enemy you can add it to a variable, right?

local function OnTouched(otherPart, Head, Torso)
		print("Touch started: " .. otherPart.Name)
		
		if otherPart == Head or Torso then
			wait(0.3)
			print("It's working")
			print(Head.Parent)
		else
			print("Try to find better")
		end
	end

This is what I wrote a script, but it does not work for me I do not understand how to distinguish between hitting the party from hitting the NPC. Immediately say that the script is local and is located at the tool.

And then how do I write what I hit into a variable?

I recommend just check name, i think you need to delete 2 last variables too :

local function OnTouched(otherPart)
if otherpart.Name == "Head" or "Torso" and otherpart.Parent:FindFirstChild("Humanoid") ~= nil then

Also sure that you added event when function call, for example if your script is in startercharacter:

script.Parent.Parent.Touched:Connect(OnTouched)

or

script.Parent.Touched:Connect(OnTouched)

(sorry, i forgot where startercharacter script go when game is running)
If anything of this didn’t work try to change local function to function