Setting a custom walk animation on a tool being equipped

Hi, I have made a custom walking animation for a sword in my game. I have this code in my sword:

local tool = script.Parent

tool.Equipped:Connect(function()
	tool.Parent.Animate.walk.WalkAnim.AnimationId = "rbxassetid://[animationID]"
end)

with the animationID being the ID I am going to use, however it does not seem to work. The animation priority is set to “Movement”. Is there a different way I should be doing this?

(edited to fix mistake)

4 Likes

Took me a while to figure this out, but onEquip is not a Event

However, Equipped is lol

local tool = script.Parent

tool.Equipped:Connect(function()
	tool.Parent.Animate.walk.WalkAnim.AnimationId = "rbxassetid://[animationID]"
end)
2 Likes

Oh OOPS that’s my bad for when I posted this - it actually is written like that in my code but I just omitted a lot of other things, so it was faster for me to just rewrite it and I just wrote it wrong when I made the post haha. So it still doesn’t work unfortunately :frowning:

Hm, are you getting any errors in the Output at all?

No errors unfortunately. I feel like I am just using the complete wrong method to do something like this

That doesn’t seem to be the case though? It looks like your script should work fine

I suppose another alternative would be is to create an Animation?

local tool = script.Parent
local Animation = Instance.new("Animation")
Animation.AnimationId = "rbxassetid://whateveranimationidishereorsomethingidk"

tool.Equipped:Connect(function()
    local Character = tool.Parent

	local Animator = Character:WaitForChild("Humanoid"):WaitForChild("Animator")
    local PlayAnim = Animator:LoadAnimation(Animation)

    PlayAnim:Play()
end)
2 Likes

If I were to do that, which does work, how would I then return to the default walking animation on unequip?

Also, should the original script that I tried have been a LocalScript?

I also have the same problem, but my animation gets stuck when i unequip the tool, what i did was change the values of the “Animate” default script inside the human, but again, I got bugged

wait wouldent it play even if you are standing still?

1 Like

Server or Local Script would work both ways

You could fire another event called the Unequipped, which is basically the opposite of what Equipped does lol & stop the animation once there’s no tool in the Character:

local tool = script.Parent
local Animation = Instance.new("Animation")
local Character, Animator, PlayAnim
Animation.AnimationId = "rbxassetid://whateveranimationidishereorsomethingidk"

tool.Equipped:Connect(function()
    Character = tool.Parent

	Animator = Character:WaitForChild("Humanoid"):WaitForChild("Animator")
    PlayAnim = Animator:LoadAnimation(Animation)

    PlayAnim:Play()
end)

tool.Unequipped:Connect(function()
    PlayAnim:Stop()
end)

I mean you could just implement a sanity check inside the Tool itself when a Character starts to move, Idk if the OP is wanting the script to play the animation when the Tool is equipped

6 Likes

Seems like it should work, but its probably going to override all other animations…

1 Like

@Hemitheos I just thought of this weird idea of switching out the default roblox “Animate” scripts inside the rig… but It might cause problems with the animation, I don’t know.

What I ended up doing so far is for the walk animation I just animated the arms into the holding position, and the legs retain the default walking animation as they are unchanged. I then play the walking animation on equip, and then stop the animation on unequip.

It’s not as smooth as I’d like but I think I’ll be able to check if the player is moving or not moving and have the correct animation play while the tool is equipped depending on their velocity

2 Likes

So you mean there is no specific way I can recreate custom animation for everytihng?

I didn’t see anyone message this, but Roblox and animations have priorities that go in a specific order of categories. Idle being the lowest action being the highest.

Try setting your animation type to “Core” since you’re changing core animations.

If this still doesn’t work, I’ll be happy to investigate the problem more tomorrow.

Have a great night.