How to adjust animation speed based on a humanoid's walkspeed?

I tried using the Humanoid.WalkSpeed property to adjust the speed but it stays the same, how do I change it?

code that i used (i defined the variables outside of the codeblock)

animationTrack:AdjustSpeed(Humanoid.WalkSpeed)

5 Likes

it stayed the same because when the humanoid walks, its walkspeed is instantly set to 16. If you’d like to use this method i would suggest tweening the walkspeed of the humanoid or make a custom movement system of some sorts. (Dont take my word on this im not a pro at scripting :sweat_smile:)

2 Likes
animationTrack:AdjustSpeed(HumanoidRootPart.Velocity.Magnitude)

Try this instead ^^

The animation now might look too quick, if thats the case then you can just divide it by a certain number until it fits

ex:

animationTrack:AdjustSpeed(HumanoidRootPart.Velocity.Magnitude/number)
10 Likes

that was supposed to be my answer, good job.

2 Likes

If your line of code is above Animation:Play() it just wouldn’t get work

You need to put the adjustSpeed code below it

(if you put it)

2 Likes

You need to play the animation track before you adjust its speed, as the previous reply mentioned.

local players = game:GetService("Players")
local player = players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://782842708"
local track = humanoid:LoadAnimation(animation)
track.Looped = true
track.Priority = Enum.AnimationPriority.Action
track:Play()

humanoid.Running:Connect(function(speed)
	track:AdjustSpeed(speed / 16)
end)

Change the divisor from 16 to some other number if you desire, I used the toy running animation to test.

7 Likes

Disclaimer:

This worked for me but I’m not sure it will work for you

(Default Animate Localscript) If you go to line 357 you should see this if statement

if currentAnimInstance and currentAnimInstance.AnimationId == "http://www.roblox.com/asset/?id=180426354" then
			setAnimationSpeed(speed / 14.5)
		end

What I did was just delete the part where it checked if the animation id is the default one

currentAnimInstance.AnimationId == "http://www.roblox.com/asset/?id=180426354"

Your new code should look like this

if currentAnimInstance then
			setAnimationSpeed(speed / 14.5)
		end

It should speed up the animation depending on your WalkSpeed now lmk if it worked!

ASSUMING IF THE ANIMATE LOCALSCRIPT HASNT BEEN ALTERED

3 Likes

try this it worked for me

Humanoid.Running:Connect(function(speed)
	RunAnimation:AdjustSpeed(Character:WaitForChild("HumanoidRootPart").Velocity.Magnitude/25) --- change this to whatever you need
end)

Multiply the Magnitude of move direction of humanoid by speed, Speed can something like (1)

Magnitude* Speed