It seems you went past the sprite limit, put this before SPSET S,Z IF S>511 THEN S=511