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)

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:)

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)
5 Likes

that was supposed to be my answer, good job.

1 Like

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)

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.

3 Likes