how to wait for an animation to finish before continuing the program

You could put a Delay node after the death animation, and put it to be as long as you need before the menu is shown.