Walking animation is stuttering when walking on a terrain

I’m having a problem with the walking/running animation, when a player or an NPC walk on a terrain the animation starts shuttering it looks like its restarting the animation over and over, i don’t know what is causing that, tried to look it up only found one post and the solution didn’t work.
what is causing that? and how can fix it?

self.humanoid.Running:Connect(function(speed)
        if speed >= self.runSpeed - 5 and self.humanoid.FloorMaterial ~= Enum.Material.Air and self._isAttackDashing == false then
            self.currentAnim:Stop();
            if self.walkAnim then
                self.walkAnim:Stop()
            end

            self.currentAnim = self.runAnim;
            self.currentAnim:Play();
        else
            if self.currentAnim == self.runAnim then
                self.currentAnim:Stop();
            end
            if speed >= self.defaultSpeed - 3 then
                self.currentAnim:Stop();
                self.currentAnim = self.walkAnim;
                self.currentAnim:Play();
            end
            if speed == 0 and self.currentAnim ~= self.CrouchAnim then
                self.currentAnim:Stop();
                if self.walkAnim then
                    self.walkAnim:Stop()
                end
                self.currentAnim = self.IdleAnim;
                self.currentAnim:Play();
            end
        end
        --print("speed = ", speed)
    end)

Desktop_2022_06_14_-_01_29_25_02_AdobeExpress