Animation not playing

I made a swing animation for my weapon but it doesnt seem to be working. On all the tutorials I watched they seem to work but for mine it, for some reason, does not.

CODE

script.Parent.Activated:Connect(function()
   local animation = script.Animation
   local humanoid = script.Parent.Parent.Humanoid
   
   local animationtrack = humanoid:LoadAnimation(animation)
   animationtrack:Play()
end)

Video

1 Like

Humanoid:LoadAnimation() is a deprecated function, your gonna have to try using Animator:LoadAnimation()

script.Parent.Activated:Connect(function()
   local animation = script.Animation
   local humanoid = script.Parent.Parent.Humanoid
   local Animator = humanoid:WaitForChild("Animator")
   
   local animationtrack = Animator:LoadAnimation(animation)
   animationtrack:Play()
end)

Still doesnt work for some reason

1 Like

If anyone could please explain why it’s not working I will be very grateful

1 Like

Does the tool actually change the .Activated property? Is the track looping?

Does the animation have the “Action” animation priority? try animationtrack.Priority = Enum.AnimationPriority.Action

Also I would not recommending reloading the animation each time you want to play it. Initilize it once then just play it each time to keep scripts clear.

Did you put AnimationId? Is it correct? Is it Animation made by you? (you can’t use animations that aren’t made by you)

Yes the animation id is correct and I made the animation.

1 Like

Are you getting any errors from this script in the output? Is this a local script?

I tried both client and server sided scripts but nothing happened. There were also no errors which I find confusing.

1 Like

OK then make it LocalScript and paste this code:

local player = game:GetService("Players").LocalPlayer
script.Parent.Activated:Connect(function()
   local animation = script.Animation
   local animator = Players.Character.Humanoid.Animator
   
   local animationtrack = animator:LoadAnimation(animation)
   animationtrack:Play()
end)

I changed some things here, but if this doesnt helps then there are other problems. Maybe your Animation is empty?

1 Like

@s0808 use @NeoBuilds script but did you forget to insert a animation into the weapon and put the animation ID into that animation?

1 Like

Yes, he did it, I asked him some time ago. Also he isn’t getting any errors, this means that Animation is inside weapon. Reasons why Animation may not work:

  • AnimationId is empty or incorrect.

  • Animation is made by other person.

  • AnimationPriority is NOT set to Action.

  • Animation is empty.

3 Likes

Aight so that worked but now the hand holding the weapon is just staying still lol

1 Like

That’s because you didn’t set AnimationPriority to Action.

1 Like

Can you tell me how to do that? I’m new to implementing animations to scripts and stuff so…

1 Like

Open your Animation in animation editor. There are 3 dots somewhere in top left corner, click on them and set AnimationPriority to Action. Save your Animation again and paste new AnimationId to Animation that is inside the script.

3 Likes