Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I make a Animation Trigger?

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?

2 answers

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.

1 comment

0

Jumpscare NPC

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.

4 comments

0

Press view source, the code is a bit messy.

0

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".

0

And when I try pasting it in a Part, it says that the animation couldn't load.

0

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.