You need to use For each. If there is only a single object type, this format works (it implicitly does the For each for you). Because you are operating on two families at once, you need to do the extra work of cycling though each object explicitly.
In the top two examples, do a For each famEnemyMelee after the Line-of-sight.
In the functions, break those apart. Have a subevent that picks the object and does its actions, then have a second subevent (at teh same level) to do the second objects actions.