# "Game Over" sound is looping

**URL:** https://forum.code.org/t/game-over-sound-is-looping/39175
**Category:** Coding and Debugging Help
**Created:** [March 20, 2024, 10:12pm UTC](https://forum.code.org/t/game-over-sound-is-looping/39175 "2024-03-20T22:12:31Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![kmorris3](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/kmorris3/32/6811_2.png) [@kmorris3](https://forum.code.org/u/kmorris3)
#### Post date: [March 20, 2024, 10:12pm UTC](https://forum.code.org/t/game-over-sound-is-looping/39175/1 "2024-03-20T22:12:31Z")

</div>

**Link to the project or level:** ([Game Lab - Code.org](https://studio.code.org/projects/gamelab/bX2ielD3Zba4HmJX3OxD48LWmEq5OQ9wCX2iB8DE3Ds))

**What I expect to happen:**  
I want the “Game Over” sound to play just once when the sprite goes off the screen

**What actually happens:**  
The sound loops (sounds like a crazy echo) because the draw loop continues iterating

**What I’ve tried:**  
I have moved the play sound block around and tried the stop sound block

---

<div class="post-metadata">

### Author: ![varrience](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/varrience/32/8042_2.png) [@varrience](https://forum.code.org/u/varrience)
#### Post date: [March 21, 2024, 3:02am UTC](https://forum.code.org/t/game-over-sound-is-looping/39175/2 "2024-03-21T03:02:01Z")

</div>

it seems like you’ve resolved your issue however you didn’t account for stopping the player from jumping after the game has finished allowing them to keep playing even though they died

```auto
// Variables
var score = -1;

// Create Sprites
var platform = createSprite(200, 200);
platform.setAnimation("platform");
platform.velocityY = 1;
platform.y = 0;
platform.x = randomNumber(50, 350);
var platform2 = createSprite(200, 200);
platform2.setAnimation("platform");
platform2.velocityY = 1;
platform2.y = 200;
platform2.x = randomNumber(50, 350);
platform.visible = false;
platform2.visible = false;
var star1 = createSprite(randomNumber(10, 390), randomNumber(-30, -100));
star1.setAnimation("star");
star1.velocityY = 3;
star1.visible = false;
var star2 = createSprite(randomNumber(10, 390), randomNumber(-30, -100));
star2.setAnimation("star");
star2.velocityY = 3;
star2.visible = false;
var player = createSprite(200, 0);
player.setAnimation("alien");
player.visible = false;
var isOver = false;
function draw() {
  // draw the background
  if (score > 25) {
    background2();
  } else if ((score > -1)) {
    background1();
  } else {
    startBackground();
  }
  if (keyWentDown("space") && !isOver) {
    score = score + 1;
    platform.visible = true;
    platform2.visible = true;
    star1.visible = true;
    star2.visible = true;
    player.visible = true;
    player.y = 0;
  }
  showScore();
  // update the sprites
  loopPlatforms();
  loopItems();
  playerFall();
  playerControl();
  playerLands();
  collectItems();
  
  drawSprites();
  gameOver();
}

// Functions
function background1() {
  background("darkBlue");
  noStroke();
  fill("yellow");
  ellipse(randomNumber(0, 400), randomNumber(0, 400), 3, 3);
  ellipse(randomNumber(0, 400), randomNumber(0, 400), 3, 3);
  ellipse(340, 50, 60, 60);
  fill("darkBlue");
  ellipse(320, 30, 60, 60);
}
function background2() {
  background("coral");
  noStroke();
  fill("yellow");
  ellipse(randomNumber(0, 400), randomNumber(0, 400), 3, 3);
  ellipse(randomNumber(0, 400), randomNumber(0, 400), 3, 3);
  ellipse(340, 50, 60, 60);
  fill("darkBlue");
  ellipse(320, 30, 60, 60);
}
function startBackground() {
  background("white");
  fill("black");
  textSize(40);
  text("Platform Jumper!!!",25, 200);
  textSize(20);
  text("Use the arrows to move the alien ",25, 250);
  text("and collect the stars.", 25, 275);
  fill("red");
  textSize(30);
  text("Press 'space' to start!", 25, 315);
}
function showScore() {
  fill("white");
  textSize(20);
  text("Score: ",10, 10, 80, 20);
  text(score, 70, 25);
}
function loopPlatforms() {
if (platform.y > 400) {
    platform.y = 0;
    platform.x = randomNumber(50, 350);
  }
if (platform2.y > 400) {
  platform2.y = 0;
  platform2.x = randomNumber(50, 350);
}
    
}
function loopItems() {
if (star1.y > 400) {
    star1.y = randomNumber(-30, -0100);
    star1.x = randomNumber(10, 390);
  }
if (star2.y > 400) {
    star2.y = randomNumber(-30, -100);
    star2.x = randomNumber(10, 390);
  }
}
function playerFall() {
  player.velocityY = player.velocityY + 0.1;
}
function playerControl() {
  if (keyDown("up")) {
    player.velocityY = player.velocityY - 0.7;
  }
  if (keyDown("left")) {
    player.x = player.x - 3;
  }
  if (keyDown("right")) {
    player.x = player.x + 3;
  }
}
function playerLands() {
  player.collide(platform);
  player.collide(platform2);
}
function collectItems() {
  if (player.isTouching(star1)) {
    score = score + 1;
    star1.y = randomNumber(-30, -0100);
    star1.x = randomNumber(10, 390);
    playSound("sound://category_achievements/lighthearted_bonus_objective_2.mp3", false);
  }
  if (player.isTouching(star2)) {
    score = score + 1;
    star2.y = randomNumber(-30, -0100);
    star2.x = randomNumber(10, 390);
    playSound("sound://category_achievements/lighthearted_bonus_objective_2.mp3", false);
  }
  
}
function gameOver() {
  if (player.y > 400) {
    background("black");
    if (!isOver) {
      playSound("sound://category_male_voiceover/mission_failed_male.mp3", false);
      isOver = !isOver;
    }
    
  }
}

```

here is my revised code hope this helps
