 <p>You should have <code>playing = false;</code><br> somewhere in game over method or somewhere else. As I see you haven't such line of code. I ask a question. Where did you change playing to false so that You expect to get</p> <pre><code> If(!playing) </code></pre> <p>Condition instead of </p> <pre><code>If(playing) </code></pre> <p>You press the key. Game begins. Now you reach </p> <pre><code>If(playing) </code></pre> <p>Then the ball get to boundaries and the code reach </p> <pre><code> if ( ballX &gt; width || ballX &lt; 0 ) { gameover = true; } // if the ball reaches one of the bounderies it will be game over </code></pre> <p>In this situation. Playing var and gameover var both are true. Right? And under </p> <pre><code>If(playing) </code></pre> <p>You have score() method.so even when gameover is true the score method still is performed.</p> <p>You can set playing to false under:</p> <pre><code>if ( ballX &gt; width || ballX &lt; 0 ) { gameover = true; Playing =false ; } </code></pre> <p>Or you can modify the score method like this:</p> <pre><code> void score () { if (playing &amp;&amp; !gameover) { fill(255); textSize(45); textAlign(CENTER); text(scorecounter, width/2,height/4); // keeps the score on the display while playing } </code></pre>