Why is my animation not playing?

I’m trying to make it where if the player is moving then an animation will play but when they stop moving the animation will stop but the animation keeps playing when i’m moving even know I added a thing that checks if it’s playing and if it is then it won’t play until next time. Any help?

spawn(function()
	while wait() do
		if script.Parent.Parent:FindFirstChildWhichIsA("Humanoid") then
			local walk = script.Parent.Parent.Humanoid:LoadAnimation(script.Parent.Walk)
			if script.Parent.Parent.Humanoid.MoveDirection.Magnitude ~= 0 then
				if walk.IsPlaying then return end
				walk:Play()
			else
				walk:Stop()
			end
		end
	end
end)
1 Like

Hello, I’m still not entirely sure what the problem is, but I do have an alternative solution to your problem. It looks like you want to set a walking animation. Coincidentally, Roblox has dedicated a developer hub page on how to change the walk animation of the players. Essentially, what you have to do is just change the walking default animation ID with the one that you want.

1. local function onCharacterAdded(character)
2. local humanoid = character:WaitForChild("Humanoid")
* for _, playingTracks in pairs(humanoid:GetPlayingAnimationTracks()) do
3. playingTracks:Stop(0)
4. end
* local animateScript = character:WaitForChild("Animate")
5. animateScript.idle.Animation1.AnimationId = "rbxassetid://(Your_animation_ID)" -- Input your animation ID
6. animateScript.idle.Animation2.AnimationId = "rbxassetid://1234509876"
7. 
8. animateScript.idle.Animation1.Weight.Value = 1 -- set to one so that this animation plays all the time
9. 
10. animateScript.idle.Animation2.Weight.Value = 0 -- set to zero to ignore second animation
11. end

This is of course most convenient if you want to permanently replace the default walking animation. May I ask if this is the case for you?

2 Likes