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)
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)
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.
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.
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()
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.