how i disable pause menu in main menu?

i have a problem with the pause menu, if i press escape in the main menu it will open the main menu as well. I tried to use an enumaration saying that when i am in the main menu it will set mainmenu value for the enumaration, if i am in the game it will set the value to ingame and that the pause menu will show up only when the value is on ingame, but it doesn’t worl. Am i doing something wrong?

Immagine 2022-11-03 150428

You need to remember what state the menus are in. Escape opens the menu during play, but returns to the previous menu in a menu ( and finally, play again ).