[SOLVED] Scene not running when going to it

Hello! How do I make it so that when I click a button to go to another scene in my project, it will reload automatically without having to reload my browser? This is the link to my project.


What happens if you change the scene to the current scene?

@Albertos If you go from the main menu to level 1 it will let you play it until the timer runs out like it is supposed to. However, if you click esc to go back to the main menu then click space and go back to the level 1, it goes to the scene but the scene does nothing.


You need to set this back to 1.

@Albertos Ok. How do I make it so that it will do this whenever I enter the scene?

You can add it to the initialize function of your timer.js script.

this.app.timeScale = 1;

@Albertos That worked in reloading it, but gave me this error

I don’t get that error. When do you get that exactly? I’m not sure what you mean with ‘reloading it’.

I only get that error when loading it the second time. I’ll play the first time like normal, go to the main menu and come back and then I get the error.

@Albertos also by reloading it I mean resetting it so that it can be played again without having to reload the browser.

I run out of time, go to menu scene and press spacebar to play again. No errors and I have 20 seconds to play again.

@Albertos Hmmm. That’s very strange. I wonder why I get that error. I’ll try reloading and playing again.

Alright, I found the error. I don’t think it’s related. Let me check.

I think it has to do with the events you use.


You need to clean up all events when you destroy the entity (which is what you actually do when you change the scene). You can try to add the code below to the initialize function, after my red line.

this.on('destroy', function() {
    this.app.off('player:score', onScoreupdate, this);


@Albertos I’m not exactly sure how that works, but I put in the code and it worked!!! Thank you very much!

1 Like

I honestly don’t know either, but luckily I do know that it has to be that way.