First: Create a Part and an Animation in your workspace.
Replace your script for this(Its like the one you posted but it works for NPCs(Yours Works for players))
1 | local part = game.Workspace.Part |
2 | local animation = game.Workspace.Animation |
5 | part.Touched:Connect( function () |
6 | local animationTrack = game.Workspace.NPC.Humanoid:LoadAnimation(animation) |
You can change the animation ID at line 3 for the ID of the animation of your choice(I made one as a sample, you can use it if you want to)
You can replace the word "NPC" at line 6 for the name of your NPC.
Now just touch the part.Here ill send some results:
Before touching it: http://prntscr.com/qdecl5
After touching it(Couldn't make a video sry): http://prntscr.com/qded0p
Contact me if you have any issues with the script.