As it shows in the image, when A key is pressed, and the sprite is visible it continues the game but if D key is pressed and sprite is visible it ends the game. But I also want to have it so that when A key is not pressed within 5 seconds it changes the scene to menu and I did so in the image but for some reason it doesn’t work, and it just changes the scene to the menu even if you have clicked A while the sprite is visible. I am most likely missing something but please someone help.
You need to understand that the wait action pauses delays the execution of the following actions in the event, but continues with the other events that follow. Then, once the wait time has elapsed, it continues with the paused set of actions.
What you want is to use a scene timer. Set it going at the start of the scene, and reset it whenever the A key is pressed. Then instead of checking is the A key is not pressed, check if the timer is greater the 5 seconds and change scene as the action. That last subevent can be removed.