Error cant open Lua Scene after opening another scene

Hi everyone, im currently working on a game project that using cocos c++ as main App and using Lua to make game that can be downloable content.

First, i want to show you game menu that will show any downloadble lua game. this menu is using c++.

Now i want to go into Game 1 that using lua and these look like the scene.

And then i back again to Menu and want to go into Lua game 2 but this is what happened.

MenuGame1.lua:18 attempt to index local 'BG' (a nil value), stack traceback: [string "C:/Users/Pc Program/.."]:51: in main chunk

the problem is, Lua engine that has been using to run Game 1 still running. its supposed to be run Game 2 now. its like lua engine not stoping after i quit from the menu.

below the code i use to run Lua


below the binding code i use to back from Lua Scene To main Scene c++

lua_register(L, "OpenSceneMenu", OpenSceneMenu);

int OpenSceneMenu(lua_State *L)
	auto sceneMenu = HelloWorld::create();
	Director::getInstance()->replaceScene(TransitionFade::create(0.15, sceneMenu));
	return 1;

My question, is there something step that i’ve been missing? maybe how to stop or reset Lua Engine ? Can anyone help me please ? Thanks anyone.

I can ask engineering if they have any thoughts.

Hi, please attach your test project, I will help you to check the problem.