I had a problem wit it too, but I resolved. My problem was that at the end of the script not all table were dropped.
After tests and retest, I undertood that, during dropping, the 'TableNumber' of existing table change!! So, if for example the number of "TableX" at the beginning is 15, during dropping can change in 10, 5,0...and when the n of your FOR is 15, the function "tablename(15)" is null.
Then I revolved using a different approach...not a cycle, but a long string.
FOR i = 0 to NoOfTables()-1
LOAD TableName($(i)) as Tablename AUTOGENERATE 1
WHERE not WildMatch(TableName($(i)), 'TableA','TableB','TableC');