Pretty simple but basically scratch will check the X & Y when you use a motion block but only when you use a Motion Block. So set size 300 and then when it reaches the edge set size 100. That tricks scratch because its not a Motion Block and it will shrink out of the screen.
I used a very clear Youtube tutorial