You can do this with only 2 actions, and without the cost of "For Each"
create a new family "SortFamily." Put the player and the trees in it
create an instance variable for the SortFamily called "SortFamilyY"
create an empty condition and add the following actions:
1. Set SortFamilyY to SortFamily.imagepointy(1)
2. Sort SortFamily Z order by SortFamily.SortFamilyY
This means every tick, the SortFamilyY variable will be set to the respective SortFamily's y position of the image point, and then the all the items in the SortFamily will be sorted
Sidenote: When you do something like this, you might realize all the different items in the family have different numbers of image points, so calling on "Image Point 3" won't be feasible, since one item already has 7 image points and another only has 1. I would recommend naming your image points instead of using numbers. "Bottom" "Top" etc