Reason for @@TRANCOUNT check?
My guess is that you are running IndexOptimize within an existing transaction.  Ola's script is checking for an open transaction close to the very start of the procedure.

Would you really want the IndexOptimize process running under ONE transaction and possibly filling up the log along with possible blocking.

Ola's code has a variety of begin transaction and commit statements.  If the process is already running under a transaction, additional begin transaction statements create nested transactions and the subsequent commit statements only decrement the @@trancount, but don't actually commit the work.

Try running the process without an explicit begin transaction.