What you see in the picture exists inside a behavior.
I duplicated the behavior, changed the flag "is selling" to be the next flag in the list which is "is buying" (flag created before making the entire behavior, that I then copied).
Then I renamed the group in the new behavior and wrote the buying logic.
After extensive bug testing, I finally solved the bug simply by recreating the lines of code in the picture from scratch.
The bug was that exiting the buying menu (deactivating the buying group), would not trigger keeping that group active.
I can not imagine it being anything else than me copying the original behavior.
Take it for what it's worth.