I put this script into each one of my 150 npcs to animate them, but it seems to not detect when the velocity of the base part has changed or something. The print does not fire. Here is my code:
local idle = Instance.new("Animation")
idle.AnimationId = "http://www.roblox.com/asset/?id=507766388"
local run = Instance.new("Animation")
run.AnimationId = "http://www.roblox.com/asset/?id=507767714"
local idleTrack = script.Parent.Humanoid:LoadAnimation(idle)
local runTrack = script.Parent.Humanoid:LoadAnimation(run)
script.Parent.UpperTorso:GetPropertyChangedSignal("Velocity"):Connect(function()
print("Fired")
local speed = script.Parent.Humanoid.MoveDirection.Magnitude
if speed > 0 then
runTrack:Play()
elseif speed == 0 then
idleTrack:Play()
end
end)
I tried detecting the movement of the npcs by making the code execute on the Humanoid.Running event, and then using the speed parameter, but that just caused all the npcs to play the running animation at all times, even when standing still.
What am I doing wrong? Is there a better way to detect when something moves?

1 comment
I don't think you need a .Magnitude for MoveDirection. If the value is changing then they're moving.