Play is not a valid member of Animation

Hello ,
I ran into problem with my animation . I got error that says

  21:21:52.679  Play is not a valid member of Animation "Workspace.EducatedPilot04.Sword1.LocalScript.Animation2"  -  Client - LocalScript:54

I look into devforum and devhub but everything is same as I did . here is the script:

local player = game.Players.LocalPlayer
local Character = player.Character or player.CharacterAdded:Wait()
local Tool = script.Parent

local animation = script:WaitForChild("Animation")
local animation2 = script:WaitForChild("Animation2")

local hum = Character:WaitForChild("Humanoid")

local trackanimation =hum:LoadAnimation(animation)
local swinganimation = hum:LoadAnimation(animation2)

function OnActivation()
	animation2:Play()
	wait(1)
	animation2:Stop()
end

function OnEquip()
	trackanimation:Play()
	
	wait(2)
	
	trackanimation:Stop()
end

Tool.Activated:Connect(OnActivation)
Tool.Equipped:Connect(OnEquip)

Any help is appreciated :slight_smile:

4 Likes

I believe you’re confused because you should use the swinganimation as it uses the LoadAnimation of animation2

1 Like

if I put this statement

local swinganimation = hum:LoadAnimation(animation2)

in this function

function OnActivation()

will it work

If you want to play the animation2, why not just use the content of OnActivation()
like this.

local player = game.Players.LocalPlayer
local Character = player.Character or player.CharacterAdded:Wait()
local Tool = script.Parent

local animation = script:WaitForChild("Animation")
local animation2 = script:WaitForChild("Animation2")

local hum = Character:WaitForChild("Humanoid")

local trackanimation =hum:LoadAnimation(animation)
local swinganimation = hum:LoadAnimation(animation2)

function OnActivation()
   swinganimation:Play()
   wait(1)
   swinganimation:Stop()
end

function OnEquip()
   trackanimation:Play()
   
   wait(2)
   
   trackanimation:Stop()
end

Tool.Activated:Connect(OnActivation)
Tool.Equipped:Connect(OnEquip)

opps silly me . I think I know why

While reading your code, I found another error that will not allow the animation to run in the game.
Remember to get the Animator of the humanoid when doing load animation.

Humanoid:LoadAnimation is deprecated.

2 Likes

I see the problem now…

You’re not using the latest method of playing an animation.

Get the Animator inside the Humanoid.

It should be look like this.

-- Snippet only

local LocalPlayer = game.Players.LocalPlayer
local Character = LocalPlayer.Character
local Humanoid = Character:FindFirstChild("Humanoid")
local Animator = Humanoid:FindFirstChild("Animator")
local DanceAnimation = script.Parent.Dance -- Sample instance only

if Humanoid then
    if Animator then
        local AnimationTrack = Animator:LoadAnimation(DanceAnimation)

        AnimationTrack:Play()
        wait(1)
        AnimationTrack:Stop()
    end
end

You are playing an animation object and not a track.

function OnActivation()
	trackanimation:Play()
	wait(1)
	swinganimation:Play()
end

If it still isn’t working your animation priority is not on action. This means other animations are overwriting it, and even though its playing you don’t see it. You can change this through the three dots in the animation editor.

Humanoid:LoadAnimation() should work even though it deprecated.

1 Like

No, Humanoid:LoadAnimation() does not work. It works in studio but not in game. The newer way to play an animation is Humanoid.Animator:LoadAnimation()

ok I think its working . just changed humanoid to animator . I it solved thanks yall :grinning:

Humanoid:LoadAnimation() should still work. I just tested it in game and studio, and playing it on both the client and server work. I’m not saying it still should be used, though.

1 Like