I have a problem with my menu

Hi I have a problem with my menu, when i click play the game starts, and when i lose i change my scene to menu but then i can’t play again. What is the problem? I have just started making games in corona. This is my level 1 code: https://paste.ofcode.org/Xrmu6hCvQrCDmTaqcsVrEe

This is menu code: https://paste.ofcode.org/tPWx7MPPN2GyBHkpQ9SQJx

And this is main.lua : https://paste.ofcode.org/HgCrUSRDYyEWHrschupkmZ

Here is video of what’s happening on menu: https://youtu.be/5npk1N0Mi9Q

Link to project files: https://drive.google.com/open?id=1fWRbs4EiHnMsm2-bsWluZS0Q1Hyx7Nih

I don’t think anyone is going to download those files and try to piece together a project to work out the issue. If you can upload the whole thing somewhere including images then maybe someone can help, or be a lot more descriptive as to what goes wrong.

I had a quick look and you do have a lot of code in scene:create that has nothing to do with creating the scene. You should only really do stuff in here that creates objects. I actually only ever call other creation functions from here, i.e. ‘createMonsters’, ‘loadBackground’, ‘drawMap’. 

Your game logic should go in separate functions outside of the composer ones. You also don’t need to remove physics using package.loaded[physics] = nil. This could be one of the problems. 

I rewrited the project and made the code cleaner, but it’s the same error, how do I stop the timer.performwithdelay function?

When setting up your timer, store a reference to it, and then use timer.cancel(myTimerReference).

https://docs.coronalabs.com/api/library/timer/cancel.html

I tried this but it didn’t worked

i put timer.pause(loop) in scene:destroy. Did I do this well?

Depends if you’re actually destroying the scene or not - this doesn’t happen by default. Have you tried it in scene:hide() ?

it’s quite working thanks but not at all, when i click play again it fades to menu

Lol i’m dumb… Thanks it’s perfectly working now!

I don’t think anyone is going to download those files and try to piece together a project to work out the issue. If you can upload the whole thing somewhere including images then maybe someone can help, or be a lot more descriptive as to what goes wrong.

I had a quick look and you do have a lot of code in scene:create that has nothing to do with creating the scene. You should only really do stuff in here that creates objects. I actually only ever call other creation functions from here, i.e. ‘createMonsters’, ‘loadBackground’, ‘drawMap’. 

Your game logic should go in separate functions outside of the composer ones. You also don’t need to remove physics using package.loaded[physics] = nil. This could be one of the problems. 

I rewrited the project and made the code cleaner, but it’s the same error, how do I stop the timer.performwithdelay function?

When setting up your timer, store a reference to it, and then use timer.cancel(myTimerReference).

https://docs.coronalabs.com/api/library/timer/cancel.html

I tried this but it didn’t worked

i put timer.pause(loop) in scene:destroy. Did I do this well?

Depends if you’re actually destroying the scene or not - this doesn’t happen by default. Have you tried it in scene:hide() ?

it’s quite working thanks but not at all, when i click play again it fades to menu

Lol i’m dumb… Thanks it’s perfectly working now!