How do i script a part so that when it gets touched it will trigger an animation?

Hello folks of the devforum. This is my first post here so my bad for any faults here.
I seek to learn how to script a part so that when it is hit, a animation will trigger on a NPC in the game.
The reason i aspire to do this is because I am working on a kind of mystery puzzle game and I want to create a cutscene where an npc moves when the character hits an invisible part. I have the cutscene down as well as the animation, now i just need to link the animation with a script and the part.
What I think I should be doing is using a hit function to trigger the animation in a script in the part. Ive tried this to no avail. Can someone help me come up with a solution?


Have you looked at this:
It basically explains how a Touch fires in both of the Parts involved and how to use it to fire another event.


I’ll have a look at it; thanks!
edit: it didnt quite give what i needed but was still helpful.

1 Like

Update: I have found the answer to what i was looking for in studio by playing around with free models.
In case your’e looking for the same answer i was its very simple: First insert a script and a part inside the npc and insert an animation as well and change the animation Id into whatever you like in the properties tab. Then inside the script follow this script and adjust it;
local hum = script.Parent.Parent.Humanoid

local anim = hum:LoadAnimation(script.Parent.Parent.yeet) --this is a variable to define where the animation is in the script, yeet is the animation’s name i chose for the animation and you can change yeet into whatever you would like in studio and it will load–

script.Parent.Touched:Connect(function() --this is to connect to the part that the script is in and then to connect and funcion whatever may be below which in this case is to play the animation–

anim:Play() --this is to play the animation–

end) --this is to end the function and without this inside the script it will break if it does not automatically insert then manually insert it–