Need Help With Making My Running Animation Work

My game currently has a script that a friend of mine made for a “Running/Dash” ability.
The script works like this:
-When the player presses the keybind (in this case, R), their walkspeed increases.
-After 5 seconds, the player’s walkspeed goes back to normal
-After 10 seconds, the player can use the ability again

https://gyazo.com/cb3da24ecdca7864405bf88d17b6e44e

(NOTE: the script for this ability is located in the “StarterGui”, as it also uses the player’s GUI to showcase stuff like how much time is left for the ability to come back, etc.)
https://gyazo.com/22a471c69f1298dffb2a75cbe51d3923

I wanted to make some changes to the script so that the animation changes whenever the player is using this ability.
My game uses custom animations and I currently input custom animations by using an “Animate” LocalScript inside of the StarterPlayerScripts.
https://gyazo.com/00a064fbdf4b452bef1db905541a1f21

I added a variable to the script that focused on the AnimationID of the player’s walking animation. I called it “currentWalkAnim”
https://gyazo.com/40b887c5ce850cf17d117701ce284079

The script was supposed to change to the new custom running animation for 5 seconds, then it would change back to the original. The issue is, the animation doesn’t change at all, it just keeps the same one as before without any changes whatsoever.

https://gyazo.com/11acbf17be82578dd5f9a41f5ad764de

https://gyazo.com/22b73ef14e586a444a1ec2cb688d7a29

All I really need is to make it so I can change the animation whenever the player presses the keybind. I’ve tried changing the script’s location to StarterCharacterScripts but it just breaks the GUI mechanic. Any ideas on how to fix this?

4 Likes

First of all, read this: AnimationPriority | Documentation - Roblox Creator Hub
In the animation editor, there is an option that you can change while editing your run animation. This allows you to choose the priority that your animation has over every other animation. So, for a running animation, you would want it at the ‘Movement’ priority or at the ‘Action’ priority, which will ensure the run animation plays instead of your regular walking animation.

Also, your animation should be in ReplicatedStorage so that it replicates across all clients and isn’t only visible locally even if you’re using a localscript. This is roughly what I use for running in my localscript.

local newrunanim = game.ReplicatedStorage.Animations.RunAnim:Clone()
newrunanim.Parent = game.ReplicatedStorage
anim = player.Character:FindFirstChild("Humanoid"):LoadAnimation(newrunanim)
anim:Play()
--change their walkspeed
wait(5)
anim:Stop
anim:Destroy()
newrunanim:Destroy()
--change walkspeed back to normal
2 Likes