Home > Software engineering >  Animation is not playing. (Roblox)
Animation is not playing. (Roblox)

Time:04-29

I am making a tool with an animation when clicked. However when I click nothing happens. I have tried 2 scripts and no errors come up but the animation doesn't play. I own the animation and other people said it worked and I don't know why it isn't for me. Here is my first script:

script.Parent.Activated:Connect(function()
        local action = script.Parent.Parent.Humanoid:LoadAnimation(script.Parent.ANIMATE)
        action:Play()
    end)

And here is my second script:

local tool = script.Parent
local animation = tool.ANIMATE

tool.Activated:Connect(function()
    local character = tool.Parent
    local humanoid = character.Humanoid

    local AnimationTrack = humanoid:LoadAnimation(animation)
    AnimationTrack:Play()
end)

Any help appreciated!

CodePudding user response:

You should of searched in the Roblox Developer Documentation and you would of found that the Humanoid:LoadAnimation() function has been deprecated.

deprecation

So you will need to use Humanoid.Animator:LoadAnimation().

script.Parent.Activated:Connect(function()
    local action = script.Parent.Parent.Humanoid.Animator:LoadAnimation(script.Parent.ANIMATE)
    action:Play()
end)
tool.Activated:Connect(function()
    local character = tool.Parent
    local humanoid = character.Humanoid

    local AnimationTrack = humanoid.Animator:LoadAnimation(animation)
    AnimationTrack:Play()
end)

CodePudding user response:

It turns out I had an animation that was exactly the same as the one I needed for a different game that I forgot about that works in my script. I have no idea what happened with the newer ones but I can finally move on!

  • Related