How can I fix this?

So I have my character and I animated a walking script for it. But when I walk this happens:
robloxapp-20210628-1147111.wmv (1.7 MB)

Here is the code:

local character = script.Parent
local Humanoid = character:WaitForChild("Humanoid")

local animation = script:WaitForChild("Animation")
local animationTrack = Humanoid.Animator:LoadAnimation(animation)

Humanoid.Running:Connect(function(speed)
	if not animationTrack.IsPlaying then
		animationTrack:Play()
	end
	if Humanoid.Running == false then
		if animationTrack.IsPlaying then
			animationTrack:Stop()
		end
	end
end)

The script is inside of StarterCharacterScripts and is local.

1 Like

Have you checked the developer hub for animations?

1 Like

What do you mean? The animation plays it is just very glitchy.

1 Like

I think this condition causes the issue. Can you change it to this?

if speed<0.1 then

Sorry for responding so late. This fixes the animation for when the player stops but not when the animation stops mid walk.

Can you try this code, I think the animation should function properly now:

local character = script.Parent
local Humanoid = character:WaitForChild("Humanoid")

local animation = script:WaitForChild("Animation")
local animationTrack = Humanoid.Animator:LoadAnimation(animation)

Humanoid.Running:Connect(function(speed)
    if speed>0.1 then
        if not animationTrack.IsPlaying then
		    animationTrack:Play()
	    end
    else
        if animationTrack.IsPlaying then
            animationTrack:Stop()
        end
end)

It still didn’t fix this. But it works none the less. Could it be a problem with my animation? The animation’s priority is movement?

I think this is the problem

being a connection or a number, it will never give false, try this and place the animation as a loop

local character = script.Parent
local Humanoid = character:WaitForChild("Humanoid")
local animation = script:WaitForChild("Animation")
local animationTrack = Humanoid.Animator:LoadAnimation(animation)

Humanoid.Running:Connect(function(speed)
    if not animationTrack.IsPlaying then
        animationTrack:Play()
    elseif speed == 0 and animationTrack.IsPlaying then
        animationTrack:Stop()
    end
end)

Also this says the API Reference

While running Humanoids cover, on average, their Humanoid.WalkSpeed in studs per second.
When the Humanoid stops running this event will fire with a speed of 0.

I was able to fix that @Bou_Baker Showed me how here:

What I need now is to fix the animation stopping while the player is still walking.

Well, in the animation settings set it to be loop.

How? There is no setting for that?
Screenshot 2021-06-29 08-43-51
These are all the settings it gives me.

In the Roblox Animation Editor load the animation and at the top, next to the time indicator, activate this button
image