Just place them in right order:
Set group "First group" deactivated
Set layer "First" invisible
Set layer "Second" visible
Set group "Second group" activated
...Or insert Wait(0.1s) if unnecessary touch still working on second layer immediately after making changes, like
Set group "First group" deactivated
Set layer "First" invisible
Set layer "Second" visible
Wait(0.1s)
Set group "Second group" activated