How i can make my turrets aim the enemy that's closest to the village?

Hello everyone, i am trying to make a TD game.
I need to make my turrets aim the enemy that’s closest to the village and i’m stuck.
My turrets aim the last enemy that enters their firing zone instead of the enemy that’s closest to the village and are in their firing zone.

Any help?

take a look here:

Thank you for your reply!
I will read the script carefully and i will learn how to do it!

Thank you!!

Edit: 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.