Hi,

the reason for this behaviour is the execution order of your functions.
If your 'attaching sword to entity' code is executed prior to your player's movement code, the sword is logically placed where the player was located one frame before.

Well, you could merge both scripts and call the attaching code right after the movement code to solve the problem.
Maybe putting the wait instruction of you attaching code right at the beginning of the while loop or using proc_late could work as well.