This is the animate script I found and I don’t know why it doesn’t work. I tried replacing RunService.Stepped:Connect(move) with RunService.Heartbeat:Connect(move) but I got the same result.
local RunService = game:GetService("RunService")
local character = script.Parent
local humanoid = character:WaitForChild("Enemy")
local walkAnim = script:WaitForChild("Walk")
local walkAnimTrack = humanoid.Animator:LoadAnimation(walkAnim)
walkAnimTrack.Priority = Enum.AnimationPriority.Movement
local idleAnim = script:WaitForChild("Idle")
local idleAnimTrack = humanoid.Animator:LoadAnimation(idleAnim)
idleAnimTrack.Priority = Enum.AnimationPriority.Idle
local function move()
if humanoid.MoveDirection.Magnitude > 0 then
if not walkAnimTrack.IsPlaying and idleAnimTrack.IsPlaying then
idleAnimTrack:Stop()
walkAnimTrack:Play()
end
else
if walkAnimTrack.IsPlaying and not idleAnimTrack.IsPlaying then
idleAnimTrack:Play()
walkAnimTrack:Stop()
end
end
end
RunService.Stepped:Connect(move)
The MoveDirection property on humanoid is only changed when the player has control of the character. Any NPC would not change that value, as it would just stay at (0, 0, 0).
You have to get the velocity by calculating it manually.
local RunService = game:GetService("RunService")
local character = script.Parent
local humanoidRootPart = character:WaitForChild("HumanoidRootPart");
local humanoid = character:WaitForChild("Enemy")
local walkAnim = script:WaitForChild("Walk")
local walkAnimTrack = humanoid.Animator:LoadAnimation(walkAnim)
walkAnimTrack.Priority = Enum.AnimationPriority.Movement
local idleAnim = script:WaitForChild("Idle")
local idleAnimTrack = humanoid.Animator:LoadAnimation(idleAnim)
idleAnimTrack.Priority = Enum.AnimationPriority.Idle
local function move()
local startPos = humanoidRootPart.Position;
local startTick = tick();
RunService.Heartbeat:Wait();
local nowPos = humanoidRootPart.Position;
local velocity = (nowPos - startPos).Magnitude / (tick() - startTick);
if (velocity > 0) then
if not walkAnimTrack.IsPlaying and idleAnimTrack.IsPlaying then
idleAnimTrack:Stop()
walkAnimTrack:Play()
end
else
if walkAnimTrack.IsPlaying and not idleAnimTrack.IsPlaying then
idleAnimTrack:Play()
walkAnimTrack:Stop()
end
end
end
RunService.Stepped:Connect(move)
Can you confirm that your animation is running at all by removing the .Stepped function and move() and just straight up play the walk and idle animations.
local RunService = game:GetService("RunService")
local character = script.Parent
local humanoid = character:WaitForChild("Enemy")
local walkAnim = script:WaitForChild("Walk")
local walkAnimTrack = humanoid.Animator:LoadAnimation(walkAnim)
walkAnimTrack.Priority = Enum.AnimationPriority.Movement
local idleAnim = script:WaitForChild("Idle")
local idleAnimTrack = humanoid.Animator:LoadAnimation(idleAnim)
idleAnimTrack.Priority = Enum.AnimationPriority.Idle
idleAnimTrack:Play()
wait(5)
idleAnimTrack:Stop()
walkAnimTrack:Play()
wait(5)
walkAnimTrack:Stop()