Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why won't the animation play when i equip the tool?

I'm trying to change the default walking animation when i equip a tool. I do this by setting the walk animation of the Animate local script that automatically gets added to the character model when they spawn in the game.

https://gyazo.com/2140d1217e4d54673e7bf4dc022fee95

Here's my code

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hum = char:WaitForChild('Humanoid')
local tool = script.Parent

tool.Equipped:Connect(function()
	
	--// The Animate local script
	local animate = char:WaitForChild('Animate')

	--// This is where i try to change the default animation
	animate.walk.WalkAnim.AnimationId = 'rbxassetid://2747459244'
	
end)

I've seen a couple posts that claims this method works but i don't understand why it's not working for me. When i click play, the animation ID changes to the one i want but the animation itself doesn't actually load.

https://gyazo.com/2a10c0792a61f673986cebaf6190ecbf

2 comments

0

Do you own the animation? Animations don't work if you you're not the owner of the animation.

0

Yes, i own the animation, i just use different accounts.

4 answers

So while you do need to do what I provided in order to get an animation to play after you change its ID, you will never be able to play an animation that is not your own. So the animation you're choosing sent me to https://www.roblox.com/library/2747459244/1H-Sword-Walk, which is not owned by you, and thus will never work.

After changing the animation ID, in order for it to actually play, you need to reload the animation:

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hum = char:WaitForChild('Humanoid')
local tool = script.Parent

tool.Equipped:Connect(function()

    --// The Animate local script
    local animate = char:WaitForChild('Animate')

    --// This is where i try to change the default animation
    animate.walk.WalkAnim.AnimationId = 'rbxassetid://2747459244'
    player.Character.Humanoid:LoadAnimation(animate.walk.WalkAnim)

end)

A more in-depth explanation of what I was saying in comments: So you have a number value object anywhere, could be in the tool or in replicate storage, it doesn't really matter. All the tool would do is:

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hum = char:WaitForChild('Humanoid')
local tool = script.Parent

tool.Equipped:Connect(function()

    --// The Animate local script
    local animate = char:WaitForChild('Animate')

    --// This is where i try to change the default animation
    numberValue.Value = theNewID

end)

then in your default animation script, you just add a listener for the value:

numberValue.Changed:Connect(function(property)
	animate.walk.WalkAnim.AnimationId = "rbxassetid://"..property.Value
        player.Character.Humanoid:LoadAnimation(animate.walk.WalkAnim)
end)

I'm thinking due to the wonky-ness of Roblox animations, you might be able to solve the problems by having the animation change from within the animation script.

7 comments

0

Yes, i own the animation, it's just on a separate account. Also it doesn't appear to be working, it changes the AnimationId, but the animation still doesn't load even when i reload the animation. No error in the output either..

0

I can confirm that the animation does in fact change cause it plays my animation when i use the Play() function, but my goal is to have it change the default walking animation so that i wouldn't need to manually play the animation track.

0

Then it must be a Roblox problem.

0

Yeah it won't work even if its on another account you own, so make sure you're logged into that account on the studio. It might just be something really simple like being logged onto the wrong account.

0

It's the right account, as i said, it works when i manually play the animation track, but that's not what i'm trying to accomplish. I'm starting to think it's a roblox problem as well...i tested it so much already. It seems like it's suppose to work but idk. Is there another method to change the walk animation the moment i equip a tool?

0

you could modify the default animation script to listen for a change in property of an object, and it changes based on the value of the object

0

and all your tool would do is change the property

Hello. Try setting the walk and run animation ids instead of just the run animation.

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hum = char:WaitForChild('Humanoid')
local tool = script.Parent

tool.Equipped:Connect(function()

    --// The Animate local script
    local animate = char:WaitForChild('Animate')

    --// This is where i try to change the default animation
    animate.walk.WalkAnim.AnimationId = 'rbxassetid://2747459244'
	animate.run.RunAnim.AnimationId = 'rbxassetid://2747459244'

end)

1 comment

0

I thought run and walk were pretty much the same thing, anyways i tested it and it didn't work, ty for the suggestion tho.

Make sure that the AnimationPriority is an action, if not do the following

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
	local hum = char:WaitForChild('Humanoid')
	local tool = script.Parent
local animation = script.Animate
	 
	tool.Equipped:Connect(function()
	 local AnimationTrack = hum:LoadAnimation(animation)
AnimationTrack.Priority = Enum.AnimationPriority.Action

AnimationTrack:Play()
end)

Hello, this is actually very simple. You don't actually need to make a new animation because the default animation will always replace your current animation if the animation is related to things like walking and running. To change the default animation, play the game in studio, then go to explorer(while playing the game) > your character in workspace > find then copy the script named "Animate". Now stop playing the game then go to explorer > StarterPlayer > StarterCharacterScripts. Then paste the script that you just copied into it, do not delete the things inside the script. Now go into the script and at line 37 & line 40 you can find the walk and run animation ids, just delete them and put your walk and run animation ids. Last thing, inside the script, find the walk and run values, inside these values there's animation, go into the animation and change the id there as well. And..you are done!

This discussion is preserved as it was. New answers, comments, and votes are closed.