Perhaps I should be more specific: how do you do so in a script.
However, it would seems the problem is something other than it failing to correctly determint a town's owner.
Just to be sure, would the following be able to identify if a town does not belong to a player: "get Town player != Player", when Player is a number? Or would it need to be done some other way?