from my experecience, when i try to switch items while moving, like rushing an abyss, it usually doesn't work and send the same error, so i have to try again.
i don't know how the packets work, but maybe you need to make the script switch when you're not moving?or pressing another key?