So are you missing some information there?
If you get a menubutton value, you'll run the appropriate subroutine, but then you set menubutton to N/A so the script won't stop in that loop. Can you post a bit more code to see what you've got as an example?
If I understand you correctly, you just need an "if" statement so that you don't overwrite the #menubutton value once "closed" has been clicked.
set #menuButton N/A
set %EndScript #false
Repeat
If #MenuButton <> N/A
{
gosub #menuButton
if #menuButton <> closed
set #menuButton N/A
}
until #menubutton = closed
halt ; End script