If touching sprite, then bounce script I use to minimise computing power and maximise accuracy. In this, script it is not possible for the balls to go out of rectangle no matter what speed!! I also used this for my covid-19 simulator, in which it was more complicated but the same basic starting script. You can also press up and down keys to change the speed!!
100% artwork and coding by me Thx for @Winkekatze for suggesting to change speed using arrow keys as well!!