It looks like you are relying on the persistence of the value of count
; however, in Google Apps Script, the global context is executed on each execution.
One option is to use the Properties Service to store the value, but in this case, you might find it more convenient to get the column hidden state by using isColumnHiddenByUser(columnPosition)
Related