I want to make a Animation Trigger for a horror game. So when Player steps on a part, a NPC will do an animation.
Can anyone help me?
In the same way you use :LoadAnimation() on a player's humanoid, you'd use it on an NPC's humanoid inside a touch event. So once touched, use :LoadAnimation() on the NPC and then just :Play() it.
Here is something that will help you. Replace the animationID variable with your own animation id.
01 | local part = script.Parent |
02 | local NPC = game.Workspace.NPC |
03 | local animationID = 1338744180 |
04 |
05 | part.Touched:connect( function (hit) |
06 | if hit.Parent:FindFirstChild( "Humanoid" ) ~ = nil then --checks if hit is a player |
07 | local Animation = Instance.new( "Animation" ,NPC) |
08 | Animation.AnimationId = "http://www.roblox.com/Asset?ID=" ..animationID |
09 | local LoadedAnimation = NPC.Humanoid:LoadAnimation(Animation) |
10 | LoadedAnimation:Play() |
11 | end |
12 | end ) |
Enjoy and thanks for posting.