I believe that your question has already been posted and answered on blenderartists here
.blend file here
what’s the difference module vs script in the logic bricks??
script is for 1 object to use, module can be used by multiple objects, so instead of 1 tower you could connect 100 to it.
#Logick Bricks : (Always -> Python-Module track_to_closest.track -> Edit object - Track_to)
# and a property "track_distance" on the object using this script
# and place a property on the objects you want to track to: called track_to
own = cont.owner
scene = own.scene
track_to = cont.actuators['track_to']
ai = [obj for obj in scene.objects if 'track_to' in obj]
closest_ai = sorted(ai, key=lambda enemy: own.getDistanceTo(enemy))
distance = own.getDistanceTo(closest_ai)
max_distance = own['track_distance']
if distance <= max_distance:
track_to.object = closest_ai