Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Npc animation script doesn't play the animation?

Asked by 4 years ago
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

Log in to vote
0
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

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)
Ad

Answer this question