Animation not playing on button click

  1. I have a script that’s meant to play an animation on the LocalPlayer when they press a button, the debug print is saying that the animation plays in the output window, however it doesn’t work and the animation does not play. I can confirm that the animation ID is correct and works - any advice or help would be appreciated, I’m a beginner scripter by the way so I’m not too sure.
local click = script.Parent.MouseButton1Click
local players = game:GetService("Players")
local char = players.LocalPlayer.Character

if not char then
    print("Waiting for character to load...")
    players.LocalPlayer.CharacterAdded:Wait()
    char = players.LocalPlayer.Character
end

local hum = char:WaitForChild("Humanoid")

local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://17426012182"

local animationTrack = hum:LoadAnimation(animation)

function playAnimation()
    print("Animation playing...")
    animationTrack:Play()
end

click:Connect(playAnimation)
  • Is this a client script?
  • Load the animation into the animator, not the humanoid

yes its a client script, how would i load it into an animator?

local animator = humanoid:FindFirstChild("Animator")

where should i put that/what do i replace with it?

put it under the humanoid declaration and then call the same function to load the animation but on the animator

really sorry could you just send the script updated with your code on it? ngl idk what any of that means again im real new to all this

local hum = char:WaitForChild("Humanoid")
local animator = hum:FindFirstChild("Animator")

local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://17426012182"

local animationTrack = animator:LoadAnimation(animation)

Maybe it’s the char variable, instead of doing what you’re doing right now, you should do:

local char = players.LocalPlayer.Character or players.LocalPlayer.CharacterAdded:Wait()

Also, make sure that the animation priority is the highest.

I believe the method of loading animation into humanoid has been deprecated and may have issues when done that way. You might have to create an Animator instance and parent it to Humanoid then load the animation into Animator the same way you would with the Humanoid.

Resource

do u mind simplifying that down to stupid level for me please, ngl when i say im a beginner i mean beginner beginner lol

I cannot seem to reproduce the issue you describe.

When testing your code with my own animation it works fine.
Are you sure it’s the right animation id and that you have access to it?

hm it must be an issue with the animation itself then, where have you put the animation and the script?

To test this myself, I simply created a ScreenGui containing a TextButton, which then contain the script. I didn’t place the animation anywhere, since it is generated by the script.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.