Hi, I have a script that determines whether the Npc is running or not, when the Npc is running the running animation plays for around 0.5 seconds then restarts.
Code:
PlayerClone:FindFirstChild("Humanoid").Running:Connect(function(speed)
if speed == 0 then
if not RunDebounce then
RunDebounce = true
PlayerClone:FindFirstChild("Humanoid"):FindFirstChild("Animator"):LoadAnimation(game.ReplicatedStorage.Animations:FindFirstChild("run")):Stop()
PlayerClone:FindFirstChild("Humanoid"):FindFirstChild("Animator"):LoadAnimation(game.ReplicatedStorage.Animations:FindFirstChild("GoodAnimsR15"):FindFirstChild("Idle1")):Play()
end
elseif speed > 0 then
if RunDebounce then
RunDebounce = false
PlayerClone:FindFirstChild("Humanoid"):FindFirstChild("Animator"):LoadAnimation(game.ReplicatedStorage.Animations:FindFirstChild("run")):Play()
PlayerClone:FindFirstChild("Humanoid"):FindFirstChild("Animator"):LoadAnimation(game.ReplicatedStorage.Animations:FindFirstChild("GoodAnimsR15"):FindFirstChild("Idle1")):Stop()
end
end
end)
you could do humanoid.Changed then check if the Humanoids MoveDirection is not equal to 0,0,0
it would probably look like this
PlayerClone:FindFirstChild("Humanoid").Changed:Connect:function()
if PlayerClone:FindFirstChild("Humanoid").MoveDirection ~= Vector3.new(0,0,0) then
--Idle
else
--Moving
end
end)
I don’t have studio open so I can’t test it rn
Also just a good habit, you can make animations Variables. this helps save memory because you don’t have to load the animation constantly and also, you can load animations Directly into the humanoids. So the final thing would look like this