How can I swap out the walking animations ingame?

Quick question, how do I swap out the animations ingame. I tried changing the Animate script, using this line of code

plr.Character.Animate.walk.WalkAnim.AnimationId = "rbxassetid://9180334045"

To change the run animation midgame, however for the change to take affect I have to stop moving and move again. How can I have this update whilst running?

Heres a quick video showing what is going on
https://streamable.com/z26j0g

2 Likes

Possibly try enabling PlatformStand:

plr.Character.Humanoid.PlatformStand = true
plr.Character.Humanoid.PlatformStand = false

This should stop all current animations and allow new ones to play, however I have never tested this before with switching animations so I can not guaranty a result sorry.

Just ran the code, nothing changed :frowning:

You can modify the Animate script to your liking. I have done this by changing the player’s walk and run animation depending on the magnitude of the velocity the HumanoidRootPart, since it is quite close to Humanoid’s WalkSpeed with a bit of imprecision. (or you can just use WalkSpeed altogether)

You can modify the “OnRunning” function in the Animate script, because it executes everytime the humanoid is running hence its connection to Humanoid’s Running event. But you have to remove the “playAnimation” function in the “move function” to mute any interruptions to the animation. By using if then statement to detect the Velocity’s Magnitude / WalkSpeed as long as the Humanoid is walking, you can set the animation to Run or Walk depending on it.

Or preferably you can modify the “move” function and instead mute the OnRunning function’s attempts to play any animations. Using the same way.

1 Like

I understand what youre saying but at the same time Im confused on it, are you able to explain a bit more?

Well, you detect the Velocity’s Magnitude or the WalkSpeed and then change the animation according to it. Such as:

if walkspeed > 16 then
--starts run animation
else
--starts walk animation
end

I can show some of my code but I thought that’d be spoonfeeding.

Nah its all good I understand. For the If statement you sent, is this something inside the animate script or do I need to add it somewhere,

You add those in functions in the Animate script, namely the “move” function or the “onRunning”.
“move” function executes constantly while “onRunning” executes as long as the player is moving.

(note that playAnimation function found in the script will not interrupt the currently playing animation if it’s the same animation)

onRunning also returns the speed of the player so you can use that instead of Velocity’s Magnitude or WalkSpeed, it is imprecise though.

To be honest I barely have any idea on how to explain it either.

there is a function in the humanoid called Humanoid.Running this function detects when the humanoid is moving

to play the anims: local WalkAnimation = Humanoid.Animator:LoadAnimation(script.WalkAnimation)

example:

Humanoid.Running:Connect(function(speed)
if speed > 0 and speed <16 then
--stop SprintAnim
 --Play walkAnim
elseif speed > 16 then
--Play SprintAnim
--Stop WalkAnim
end

I tried something similar to this, and it works except it doesnt go back to the walking animation/idle

@MemezyDev edited some stuff

Humanoid.Running:Connect(function(speed)
if speed > 0 and speed <16 then
--stop idle
--stop SprintAnim
 --Play walkAnim
elseif speed > 16 then
--stop idle
--Play SprintAnim
--Stop WalkAnim
elseif speed <= 0 then
--Idle Play
--Stop walk
--stop Sprint
end
3 Likes

This might not make anything sense but maybe it’s just because the WalkAnimation just takes a long time/slow response to change the id of the Walk Animation that’s why you are required to stop?

local animId = 9180334045

local isRunning = false

Game:GetService("RunService").RenderStepped:Connect(function()
      if walkspeed > 16 or isRunning == true then --or whatever you call it when you run
              plr.Character.Animate.walk.WalkAnim.AnimationId = "rbxassetid://"..animId
     end
end

This is just my Idea, Using the RenderStepped to constantly change the ID of the animation to make sure the WalkAnimation is Automatically changed.

1 Like

This didnt change anything, the same issue occurs :frowning:

I dont think this would be very resource friendly if its constantly checking the walkspeed every frame

How about trying it first? then if it works you can have a Different Idea which is similar to this one as well

Also if you don’t want the walk speed to be checked every frame what about just a variable containing to check whether the Player is sprinting or not or probably make a Variable named Connection and connecting it to the renderstepped and just Disconnecting it if the player’s walk speed is less than 16 or the Variable containing the Sprint is false

show me the code you used for it

Nvm I was messing with the code and found out the walkspeed is a little off, when I expected it to be 10 it was 10.2. I edited the code you sent and it worked great. Thanks :slight_smile:

1 Like

you can directly set the walk animation also, if you look in the animate script, there are variables for each animationId. Changing those will change the actual animations

nice. since its solved just mark my post as solution

Ye I already did, quick question thouygh. Would it be a similar process to change the idle animation, or would it be something different?

1 Like