I found that for some reason having variables outside a function won’t work. So you need to have all variables contained within functions and the simple trigger onOpen() should work. I found the above explained here: https://stackoverflow.com/a/59227643/10312679
But I didn’t want to rewrite my script so I found this solution that overrides the above problem. You just manually create an onOpen trigger under the trigger settings of the project/script as explained here: https://stackoverflow.com/a/13527430/10312679
CLICK HERE to find out more related problems solutions.