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?
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.
local part = script.Parent
local NPC = game.Workspace.NPC
local animationID = 1338744180
part.Touched:connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") ~= nil then --checks if hit is a player
local Animation = Instance.new("Animation",NPC)
Animation.AnimationId = "http://www.roblox.com/Asset?ID="..animationID
local LoadedAnimation = NPC.Humanoid:LoadAnimation(Animation)
LoadedAnimation:Play()
end
end)
Enjoy and thanks for posting.
Press view source, the code is a bit messy.
Thank you for your help, but when I try pasting the code into my NPC it says "Touched is not a valid member of Model".
And when I try pasting it in a Part, it says that the animation couldn't load.
O_3I Try pasting the script in the humanoid of the NPC
This discussion is preserved as it was. New answers, comments, and votes are closed.
1 comment
Jumpscare NPC