Need Help with Piezo Buzzer and Ultrasonic Sensor code

Nevermind about distance vs lastDistance, I was confusing myself because I realized on the very first reading lastDistance would have no value, but every reading after that it would be different or the same from the distance value.

The Hysteresis variable makes it so it only triggers the loop if the distance has changed 'x' amount. What's perplexing though, is values of 1 or 10 for hysteresis seem to do the same thing and maybe it's just a crap sensor but it doesn't seem to respond when it should and it goes crazy beeping and flashing unexpectedly.

The serial monitor works, here is an example with Hysteresis set at 10:

5 cm
7 cm
6 cm
6 cm
6 cm
6 cm
6 cm
6 cm
6 cm
6 cm
Out of range
6 cm
6 cm
Out of range
6 cm