Why is my character's tool animations script not working?

So I made two animations for the character to use while having the tool equippedone for walking and the other for idle, however the script is not working for some reason and is playing,both the default walking animation and the tool walking animation at the same time.
The default walking animation is being played on another script,I tried disabling that script but did’nt work.
Here’s the script.

local Player = game:GetService("Players").LocalPlayer          -----------Getting the animator and the character animations through variables
local char = Player.Character or Player.CharacterAdded:Wait()
local humanoid = char.Humanoid
local animator = humanoid.Animator
local PIDL = script.PistolIdle
local PidlAnimationTrack = animator:LoadAnimation(PIDL)    --Idle character animation while using the tool
local PWal = script.Pistolwalking
local PWalAnimationTrack = animator:LoadAnimation(PWal)           --Walking character animation while using the tool
local wal = game.StarterPlayer.StarterCharacterScripts.WalkingAnimation.Walking  --Walking animation
local walAnimationTrack = animator:LoadAnimation(wal)
---------------------------------------------------------------------------------
script.Parent.Equipped:Connect(function()
	PidlAnimationTrack:Play()
	walAnimationTrack:Stop()
	if humanoid.MoveDirection.Magnitude > 0 then
		PWalAnimationTrack:Play()
		PidlAnimationTrack:Stop()
	end
end)

script.Parent.Unequipped:Connect(function()
	PWalAnimationTrack:Stop()	
	walAnimationTrack:Play()
	PidlAnimationTrack:Stop()
end)

Also this script is a local script inside the tool btw.

The default walk animation plays from the Animate script that is automatically put in players’ characters.

You can override the default walking animation by getting the track for it and stopping it (it might just start playing again, idk–people don’t really do this), or you could make your walking animation have a higher priority (and act on all joints) (also not recommended).

What most people do (as far as I know at least) is they replace the walking animation in the Animate script, then replace it when the tool is unequipped.

So along the lines of:

  • Get the walk and run animations under the character’s animate script
  • Replace the two animations with your walking animation on equip
  • On unequip put the original animations back in the walk and run Value instances

Another benefit of doing it this way is this automatically scales the speed of your animation to the movement.

1 Like

Well,I simplified the script a little and changed the animation’s priorities (I changed the fefault walking animation’s priority in it’s own script),but still it ain’t working in the output it prints
PLay is not a valid member of AnimationTrack “PistolIdle” for some reason .

local Player = game:GetService("Players").LocalPlayer          -----------Getting the animator and the character animations through variables
local char = Player.Character or Player.CharacterAdded:Wait()
local humanoid = char.Humanoid
local animator = humanoid.Animator
----------------------------------------------------------
local PIdl = script.PistolIdle
local PIdlAnimationTrack = animator:LoadAnimation(PIdl)
----------------------------------------------------------
local PWal = script.Pistolwalking
local PWalAnimationTrack = animator:LoadAnimation(PWal)
---------------------------------------------------------------------------------
PWalAnimationTrack.Priority = Enum.AnimationPriority.Action2
PIdlAnimationTrack.Priority = Enum.AnimationPriority.Action

if script.Parent.Equipped then
	PIdlAnimationTrack:PLay()	
	PWalAnimationTrack:Play()
else
	PIdlAnimationTrack:Stop()
	PWalAnimationTrack:Stop()
end	

if script.Parent.Unequipped then
		PIdlAnimationTrack:Stop()
		PWalAnimationTrack:Stop()
end
------------------------------------------------------------------

There’s just a small typo, the L in Play needs to be lower case.

2 Likes

Seems that another cause was that I had to put the animations inside the tool and not inside the script,doing that fixed the problem,thanks anyways.

2 Likes