Figured it out, appologies.
I removed all the end if's to make it a complete if statement. Set the global variable on the first script used declaring the value as 0. Then later when incrementing it is adding to a previously defined global variable of the same name.
I believe my problem lay in global variable instances default value being void.