Just two comments:
1. To make the while-loop work like a trigger the line containing nearestObjects should be inside the loop not outside.
2. If possible try to avoid using nearestObjects with "ALL". Be as specific as possible. This won't speed up the nearestObject command but it will speed up the processing of the returned list!
For example, using [...,["ALL"], 500] on an empty map in downtown Paraiso returns more than 700 objects (like road signs, insects, trees, park benches, walls, etc) and all of them would have to be checked for being opfor. Whereas using a slightly more sophisticated "filter" like [...,["AllVehicles"], 500] reduces this number to one here (the player's unit since the map is still empty).