Idle animation stops playing after walking

What I’m attempting to achieve
I have a tool/weapon that has an idle animation, and I’m trying to make it so that the idle animation plays whenever my character isn’t moving.

ISSUE
The idle animation plays when I equip the weapon, but after I walk or run, the idle animation doesn’t play until I re-equip the tool. I tried to modify the script with a ‘renderstepped’ function, but it still doesn’t seem to work.

This is the part of the script that doesn’t work:

RunService.RenderStepped:Connect(function()
	local humanoid = character:FindFirstChildOfClass("Humanoid") or character:FindFirstChildOfClass("AnimationController")
	local animator = humanoid:FindFirstChildOfClass("Animator")
	
	if humanoid.MoveDirection.Magnitude > 0 then
		if track then
			track:stop()
			if humanoid.MoveDirection == Vector3.new(0,0,0) then
				for i,v in ipairs(animator:GetPlayingAnimationTracks()) do
					v:Stop()
				track:play()
				end
			end
		end
	end
end)

I believe it has to be capitalized Play?

and wont hurt to capitalize this Stop too.

I made it capital, but the same result is there

any errors in output window? . . . .

No, it comes up with nothing when I test.

Add some print statements to see where in the code it is not working… sorry your video clip doesnt load for me, nothing happens when i try to click that blue link.

This is the point where the code stops working

1 Like

Try looking at this thread with a similar issue and how they resolved:

You’re checking if MoveDirection.Magnitude == 0 within the check to see if MoveDirection.Magnitude > 0. It’s either one, or the other.

Swap your code to this and let me know if it works.

RunService.RenderStepped:Connect(function()
	local humanoid = character:FindFirstChildOfClass("Humanoid") or character:FindFirstChildOfClass("AnimationController")
	local animator = humanoid:FindFirstChildOfClass("Animator")

	if humanoid.MoveDirection.Magnitude > 0 and track.IsPlaying then
		track:Stop()
		
	elseif humanoid.MoveDirection.Magnitude == 0 and not track.IsPlaying then
		for i,v in ipairs(animator:GetPlayingAnimationTracks()) do
			v:Stop()
			
		end
		
		track:Play()
	end
end)
1 Like

Thanks, I got an error in the output window (I’m not sure why), but the code worked! :+1: :slight_smile: