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

Npc animation script doesn't play the animation?

local npc1 = game.Workspace.OldMan

script.Parent.Touched:Connect(function()
	
	local Animation = Instance.new("Animation",npc1)
	Animation.Name = "LookAnim1"
	
	local Anim = require(game.Workspace.AnimationID)

	Animation.AnimationId = Anim.LookAfterEntering
	
	local Humanoid = npc1:WaitForChild("Humanoid")
	
	
	Humanoid:LoadAnimation(Animation)
	
	Animation:Play()
end)

Here is my script, I'm trying to make a touched event that will make an npc do an animation. But the output says "Play is not a valid member of Animation".

I hope somebody can help me, thanks!

1 answer

✓ Accepted answer

You need to call the :Play() method on the AnimationTrack Instance returned from the :LoadAnimation() function called on the Humanoid:

local Anim = require(workspace.AnimationID)

local OldMan = workspace.OldMan

local Part = script.Parent

Part.Touched:Connect(function()
	local Animation = Instance.new("Animation")
	Animation.Name = "LookAnim1"
	Animation.AnimationId = Anim.LookAfterEntering
	Animation.Parent = OldMan

    local Humanoid = OldMan:WaitForChild("Humanoid")
	local Track = Humanoid:LoadAnimation(Animation)
	Track:Play()
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.