Code gets stuck on the last note of the melody after being played

Thank you for telling me, I edited the original post to include those. Unfortunately the bot detected it as spam for a while, but all is good!