Exexute Mission Lua Scripting

Hi ,
I want to use Lua Scripting to execute Mission for copter with X frame , When i arm the vehicle and do takeoff in Guide Mode and i want to switch to auto mode i have error : Auto mode:init failed .
i want to know , how to do this and what command should i use to do this.
thanks
I would be happy if some ‘lua-masters’ like @Yuri_Rage or @Randy Mackay or everybody else could have a look on it and give me feedback on dangerous things or constructs I could not see yet or things I could improve.