Remove Self question

So i am trying to create a in game menu. I am able to create my menu when clicking my pause game button. this is all great until i want to close out my menu and go back to playing the game. here is what i have happening in my close menu function:

local closeMenuBtn  
  
 local closeMenuBtn = function ( event )  
 if event.phase == "release" then  
 menubg:removeSelf() ; menubg = nil  
 replayBtn:removeSelf() ; replayBtn = nil  
 LevelSelectBtn:removeSelf() ; LevelSelectBtn = nil  
 closeMenuBtn:removeSelf() ; closeMenuBtn = nil  
 physics.start()  
 end  
end  

i always get the error: attempt to index upvalue ‘closeMenuBtn’ (a nil value)

i can’t figure it out, i have looked at the monsters vs zombies example and this is how they do it also. Anyone have any ideas of how to do this? it just seems to not want to destroy the button that i just used to start the removeself function…
[import]uid: 19620 topic_id: 7281 reply_id: 307281[/import]

that code doesn’t make sense you’ve got closeMenuBtn defined as both a function and presumably also a button. you can’t have the same name for a function and a display object within the same scope
[import]uid: 6645 topic_id: 7281 reply_id: 25598[/import]

haha your right, my mistake, i got all that sorted out and im finally not getting any errors but now when i hit my close menu button everything changes slightly as far as the alpha, but it does not actually stop displaying my menu components… [import]uid: 19620 topic_id: 7281 reply_id: 25615[/import]

there was no alpha in the code you posted, so i don’t know what you’re doing there [import]uid: 6645 topic_id: 7281 reply_id: 25619[/import]

Okay i figured it out, turns out that i was not using the on event.phase “release” so when i would click my menu button it displayed 2 layers of my menu, so when i would click close there would still be 1 set of my menu components visible. Thanks for your help jmp [import]uid: 19620 topic_id: 7281 reply_id: 25621[/import]

when using the UI library, in the creation of your button you define a “id” do you use this id name whenever you are refering to that button? or what is the point of this? [import]uid: 19620 topic_id: 7281 reply_id: 25717[/import]