How to animate walking R15 NPCs according to walkspeed

Hello, I’ve been trying to make NPCs (R15) play a walking animation according to walking speed, so that
if I set the walking speed higher the NPC will not look like they are walking slowly.

I have very litte experience with animations

I already have the NPC and the animation, just need the animation to sync with the walking. Thank you in advance!

2 Likes

Just a possible idea
you could use some sort of RunService.Heartbeat connect function for something to run every frame and continuously check the walkspeed property of the Humanoid of every player, on the Client to remove unnecessary replication , and when the walkspeed value is lesser than a set value, such as 15, the animation that’s supposed to run at slower speeds plays.

Heartbeat because it fires every frame and depends on the performance of the local Client’s own machine.

I am trying to play the animation on a NPC while it is walking, not for players.

Could you elaborate on animation speeds?

You can try adding a script in the NPC thats looping every milisecond to check the Humanoid walkspeed like

while wait() do
  if script.Parent.Humanoid.WalkSpeed >= 20 then
    YourAnimation:Play()
``` Thats all I can think of

Sorry, but that isn’t what I meant. I wanted to adjust a animations speed based on a humanoid.

All i know is that there is someway to adjust the speed of an animation, and was looking for a way to utilize that.

It’s ok though, I’ve found a way to do it.

P.S your code wouldn’t work if you declared speed before the loop, as that will only set the variable to the walkspeed the humanoid had when the script ran the first time. No offense, just wanted to point that out as it confused me at first aswell.

local npc_humanoid = workspace.npc.Humanoid;


npc_humanoid.Running:connect(function(speed)
    animation:AdjustSpeed() --// Your own math
end)

here is some more documentary for an animation and setting:
Track: AnimationTrack | Documentation - Roblox Creator Hub
AjustSpeed: AnimationTrack | Documentation - Roblox Creator Hub
AjustWeight: AnimationTrack | Documentation - Roblox Creator Hub
These are the most likely you’d want to use.

1 Like

@EmeraldLimes

Yeah I accidentally put it before the loop,
If you declare a variable before you start reiteration , that stored value will be used not the constantly changing one

1 Like