Need Help with Piezo Buzzer and Ultrasonic Sensor code

I put the

delay(500);

back at the bottom and the buzzer now works, but it is a constant buzz instead of being interrupted no matter what I point the sensor at.

EDIT: ignore this post, pretty sure on this specific test I put the wire in the power rail instead of the signal rail. But all other tests I double and triple checked my wires were correct.