Changing The Character Animation When A Tool Is Equipped

Hi im recently making a game with a costume character. I need that when the player equip a Sword the character change animatio to the sword run animation, but i really don’t know how to do it.

This is the part of the script Animation that i tryied to change, but it doesn’t work. Can anyone help me?

function onRunning(speed)
if speed > 0.01 then
if script.Parent.Sword == false then
playAnimation(“walk”, 0.1, Humanoid)
if currentAnimInstance and currentAnimInstance.AnimationId == “http://www.roblox.com/asset/?id=180426354” then
setAnimationSpeed(speed / 14.5)
end
pose = “Running”
else
playAnimation(“sword”, 0.1, Humanoid)
if currentAnimInstance and currentAnimInstance.AnimationId == “http://www.roblox.com/asset/?id=180426354” then
setAnimationSpeed(speed / 14.5)
end
pose = “Sording”
end
else
if emoteNames[currentAnim] == nil then
playAnimation(“idle”, 0.1, Humanoid)
pose = “Standing”
end
end
end

I added a new animation on the top of the script that is called “run”, i added a StringValue parented with the Animation script that as an Animation with the Run animation id and i added in the StarterCharacterScript a boolValue called “Sword” that is true when the player equip the sword, but the sword animation get played even if the of “Sword” is set to false.

This is a short video to clear the ideas.