What you did is not right, the new code has essentially the same problem as in your first comment. If there are several bad troops within 500px from the good guy, the first badtroops instance will be picked as a target. Not necessarily the nearest. And if several good guys see the same bad guys, they will all pick the same one badtroops instance.
Also, there is no point in using TargetUID variable if you are refreshing targets on every tick. The whole idea is to prevent this - once a goodtroop has a target, it will stick to it and will not be distracted by other targets.
Picking by comparing distance is the same as using LOS behavior, but the LOS behavior works faster.
Finally, your events 8 and 9 are also very wrong. They shouldn't be nested inside the loop. I suggest using Timer behavior to shoot a bullet.
Here is how I would do the whole thing: