Hey so I’m making an NPC system, however the run animation keeps playing and won’t stop. Script is below.
local randomNPC = script.Parent
local runAnim = randomNPC.Humanoid:LoadAnimation(randomNPC:FindFirstChild('RunAnim'))
local idleAnim = randomNPC.Humanoid:LoadAnimation(randomNPC:FindFirstChild('IdleAnim'))
randomNPC:FindFirstChild('Humanoid').StateChanged:Connect(function(oldstate,newState)
if newState ~= Enum.HumanoidStateType.Running then
local animationTracks = randomNPC:FindFirstChild('Humanoid'):GetPlayingAnimationTracks()
for _,tracks in pairs(animationTracks) do
if tracks.IsPlaying == true then
tracks:Stop()
end
end
else
runAnim:Play()
end
end)
Any help would be highly appreciated!