Animation doesn't play when NPC is Touched

image
I want it so if a player touches the NPC an animation would play. It won’t work. Any help would be appreciated.

local scarything = script.Parent
local scaryanimation = script.Parent.Animation

scarything.Touched:Connect(function(p)
	
	scaryanimation:Play()
end)

image

1 Like
1 Like

Try this and tell me if it works:

local scarything = script.Parent
local humanoid = scarything.Humanoid
local Animation = script.Parent.Animation

scarything.Touched:Connect(function(p)
	local scaryanimation = humanoid:LoadAnimation(Animation)
	scaryanimation:Play()
end)

It should work, this should play the animation when scarything touches anything.

I tried the script and it didn’t work
https://i.gyazo.com/d6bbfd4436201d6386d04ec563a1752e.mp4

Is the NPC anchored? If you want it to stay in place, anchor the root part only.

Are you sure about the following?

  • You put the animation ID inside the animation correctly?

  • The animation length is long and not very short because it could have played and finished before your character even loaded into the game because you don’t have any if statements or anything that checks if the NPC touched a specific part or any player since you don’t it will run instantly because the NPC is touching the ground from the start since you put it on the ground?

  • The animation inside the variable is the same as the name of your animation and the :LoadAnimation() is the same name as the animation variable?

Yes the animation ID is correctly placed
image

Yeah I tried many different animations from different lengths and the result was still the same.

The animation variables I believe are working
image
image

The reason why it’s not working is because there’s simply no Touched event inside Models if you had your output opened you would notice that it would give you an error saying:

Touched is not a valid member of Model

I didn’t notice this because I didn’t actually test it in studio but when you told me that it was not working I got confused about why it was not working and I decided to test it in studio.

So you need to find out what you want to use to make the animation play, if you need help finding out what things do/have then open the Object Browser or go to Roblox Engine API Reference | Documentation - Roblox Creator Hub to know about them.

I think he should anchor only the root part in the npc.