How do I change player animation when equipping a tool

Hi,

I was trying to make a sword and I want it to have animations when the player equip it
I added idle animation but I do not know how to change the player’s walking animation
not only the player walk animation but also other animations such as jump, fall, and run.

I try adding when ever the player is moving it will player the walking animation but it turnout
to be bad and glitchy.

thank you in advanced :slight_smile:

Maybe this works

1 Like

I already try that method but it still doesn’t work…

This works but the problem is that i think you have to upload the animations in this way or else it wont play the animation

local HumDesc = Humanoid:GetAppliedDescription()
HumDesc.ClimbAnimation = 619521311
Humanoid:ApplyDescription(HumDesc)

I think i’ve found the best way

script.Parent.Equipped:Connect(function()
	local humanoid = game.Players.LocalPlayer.Character.Humanoid
	for _, playingTracks in pairs(humanoid:GetPlayingAnimationTracks()) do
		playingTracks:Stop(0)
	end
	local Anim = humanoid:LoadAnimation(script.Parent.Animation)
	Anim:Play()
end)

This will stop the playing animations and then it plays a custom animation

You can find other ways to do it in here: Using Animations | Roblox Creator Documentation

1 Like

sorry for the late response does it work in all animations like running and jumping etc.?

It stops all the playing animations

is there anyway to stop the animation when unequipping?

local Anim
script.Parent.Equipped:Connect(function()
 local humanoid = game.Players.LocalPlayer.Character.Humanoid
 for _, playingTracks in pairs(humanoid:GetPlayingAnimationTracks()) do
	playingTracks:Stop(0)
 end
 Anim = humanoid:LoadAnimation(script.Parent.Animation)
 Anim:Play()
end)

script.Parent.Unequipped:Connect(function()
  Anim:Stop()
end)

the script is very glitchy I was going for walk animation first
and it ended up not well
I wanted the walk animation to play when the player is walking
not play the animation when the player is equipping

You can stop the default animations everytime the player jumps or walks and play your custom animation

Like this

humanoid.StateChanged:Connect(function(state)
 if state == Enum.HumanoidStateType.Running then
  Anim:Play()
 end
end)
1 Like

Couldn’t he just change the default animation IDs from the script like this?
Only downside is that OP has to do this for every animation that he wants to override. But it is accurate:

tool.Equipped:Connect(function()
    game.Players.LocalPlayer.Character.Animate.idle.Animation1.AnimationId = "rbxassetid//your_id_here"
end)
tool.Unequipped:Connect(function()
    game.Players.LocalPlayer.Character.Animate.idle.Animation1.AnimationId = "http://www.roblox.com/asset/?id=1083445855" --default id
end)
6 Likes

He said he tried that already, but it didn’t worked

But i’ll try to find a way to fix it

Edit:
nvm it works

1 Like

it worked what?
i think i did something wrong when i try that solution

it doesnt work for me? It just doesnt update it. i mean it changes the id but the animations dont update.

Or I mean, I ant it to update while im walking, instead of me having the stand still for it to update

that’s because the animate script updates animations when humanoid’s state is changed
so after changing the animations you have to change the humanoid state

example:

Character.Animate.idle.Animation1.AnimationId = "http://www.roblox.com/asset/?id=1083445855"

Humanoid:ChangeState(Enum.HumanoidStateType.Landed)
2 Likes

yo, been a hot minute. anyway I can modify this to be a gui instead? i want a walk/run mobile textbutton for those who cant press the shift button. I don’t know how to make it so when you press the button, your animation shall switch

I FIGURED IT OUT!!! FINALLY OMG

local Player = game.Players.LocalPlayer

repeat wait() until Player.Character

local Character = Player.Character

local Humanoid = Character:FindFirstChild(“Humanoid”)

local Animation = Humanoid:LoadAnimation(script.Animation)

tool = script.Parent

tool.Equipped:Connect(function()

game.Players.LocalPlayer.Character.Animate.walk.WalkAnim.AnimationId = “rbxassetid://10478382029”

Humanoid:ChangeState(Enum.HumanoidStateType.Landed)

end)

tool.Unequipped:Connect(function()

game.Players.LocalPlayer.Character.Animate.walk.WalkAnim.AnimationId = “rbxassetid://10443472990” --default id

Humanoid:ChangeState(Enum.HumanoidStateType.Landed)

end)

3 Likes