Animation randomly breaks when finishing

For some reason my running animation begun just twitching whenever it loops, here’s a video of how it happens:

https://gyazo.com/c21f03aa79acb321631ecb677e584335

It randomly snaps to this frame which also moves the torso upwards, I’m using a script to handle the animation replacing but the only line that ever messes with it is commented out.
image

It didn’t happen until today when I decided to change the animation, twitching never appears in animation editor and I’ve modified it so many times but it never stops happening.

I think it might be related to the fact my starter character’s legs are jointed to the humanoid root part and not the torso since the rig I used to animate has that so it’s easier to move the legs and torso freely, but I don’t know how I would go about doing something about it and I really don’t want to remake all the animations I’ve made to go back to a normal rig.