Can someone here help me with a distance check please? thx

If you follow the logic a little closer (the white lines) you’ll see that it does not match what you describe.

What it does do is check if P00 exists, if so get its distance and then immediately move on to the comparison (again P01Distance which has not been set here and will have whatever value it previously had). If P00 does not exist, then checks if P01 does and sets its distance and then moves on to the comparison (against P00Distance which was not set here…).

You need to move things around so you always to both sets before the comparison, and use the false branches from the existence checks to return something sensible and not compare.