What's wrong with my Javascript GD2 final level? The database won't record

I need help figuring out why the game won’t register when I defeat or collect something, here is my formatted code:

// Create your own game!
// Spawn a player with spawnPlayerXY()
var player = game.spawnPlayerXY("knight", 40, 8);
player.maxSpeed = 20;
player.attackDamage = 90;
// Add at least one goal!
game.addCollectGoal();
var goal = game.addManualGoal("Defeat 15 Munchkins!");
game.addSurviveGoal();
// Spawn objects into the game with spawnXY()
//forests
game.spawnXY("forest", 40, 48);
game.spawnXY("forest", 40, 32);
game.spawnXY("forest", 40, 18);
game.spawnXY("forest", 58, 32);
game.spawnXY("forest", 22, 32);
game.spawnXY("forest", 18, 32);
game.spawnXY("forest", 64, 32);
game.spawnXY("forest", 72, 60);
game.spawnXY("forest", 64, 60);
game.spawnXY("forest", 72, 52);
game.spawnXY("forest", 64, 52);
game.spawnXY("forest", 58, 60);
game.spawnXY("forest", 58, 52);
game.spawnXY("forest", 72, 8);
game.spawnXY("forest", 72, 16);
game.spawnXY("forest", 64, 8);
game.spawnXY("forest", 64, 16);
game.spawnXY("forest", 58, 8);
game.spawnXY("forest", 58, 16);
game.spawnXY("forest", 8, 8);
game.spawnXY("forest", 16, 8);
game.spawnXY("forest", 22, 8);
game.spawnXY("forest", 22, 16);
game.spawnXY("forest", 8, 16);
game.spawnXY("forest", 16, 16);
game.spawnXY("forest", 8, 60);
game.spawnXY("forest", 8, 52);
game.spawnXY("forest", 16, 52);
game.spawnXY("forest", 16, 60);
game.spawnXY("forest", 22, 52);
game.spawnXY("forest", 22, 60);
// enemies
var generator1 = game.spawnXY("generator", 40, 60);
generator1.maxHealth = 500;
generator1.spawnType = "munchkin";
var generator2 = game.spawnXY("generator", 70, 42);
generator2.maxHealth = 500;
generator2.spawnType = "munchkin";
game.spawnXY("munchkin", 8, 42);
game.spawnXY("munchkin", 10, 42);
game.spawnXY("munchkin", 12, 42);
game.spawnXY("munchkin", 14, 42);
//gems&chest
game.spawnXY("chest", 8, 32);
game.spawnXY("gem", 8, 40);
game.spawnXY("gem", 8, 24);
game.spawnXY("gem", 72, 40);
game.spawnXY("gem", 72, 24);
game.spawnXY("gem", 16, 40);
game.spawnXY("gem", 30, 32);
game.spawnXY("gem", 16, 24);
game.spawnXY("gem", 24, 24);
game.spawnXY("gem", 24, 40);
game.spawnXY("gem", 64, 40);
game.spawnXY("gem", 64, 24);
game.spawnXY("gem", 56, 40);
game.spawnXY("gem", 56, 24);
game.spawnXY("gem", 50, 32);
game.spawnXY("gem", 40, 40);
game.spawnXY("gem", 40, 24);
game.spawnXY("gem", 30, 24);
game.spawnXY("gem", 50, 24);
game.spawnXY("gem", 50, 40);
game.spawnXY("gem", 30, 40);
game.spawnXY("gem", 30, 16);
game.spawnXY("gem", 50, 16);
game.spawnXY("gem", 30, 50);
game.spawnXY("gem", 50, 50);
//health potion
game.spawnXY("potion-medium", 72, 32);
//ui tracker
ui.track(game, "time");
ui.track(game, "defeated");
ui.track(game, "collected");
//function
function checkGoal() {
    if (game.defeated > 14) {
        game.setGoalState(goal, true);
    }
}
while (true) {
    checkGoal();
}

Hey @Georgia_Moore! Welcome to the discourse. When you made a manual goal, you didn’t write down how it gets completed. That might be why nothing works. If you don’t remember how to make the manual goal function, you can refer back to Level 15: Stick Shift.

Thank you so much for helping, that makes sense.

No problem! If this is solved can you please mark my post as the Solution so this topic is closed? Unless there is another problem you have on the this level of course. :slight_smile:

@moderators could you please close this topic since it’s solved?