problem loading local variable into a custom attributes

I scripted a custom attributes that looks like:

MyAttr = attributes BoutonPropsAttr 
( 
     local LayerBags= layermanager.getLayerFromName "PropsBags"
     local LBagsState = LayerBags.on
 
 
 rollout blabla "blabla" 
  ( 
     	checkbox bags "bags"  checked:LBagsState
												                   on bags changed theState do 
												if LayerBags.on == true then LayerBags.on = false  
												else LayerBags.on = true    
 
  )
 
 )

when I evaluate the script and add it to a controller I get no errors. However as soon as on the checkbox I get a plug-in error -- runtime error: Plug-in not active, unable to access plug-in local or paramater LBagsState

If I dont add those local value before my rollout I get a missing .dll error when I reopen max and reload the scene.