3.4 variable errors

I’ve been using this script to adjust the main camera to point at ALL target objects in a racing game. All was fine in 3.3 but 3.4 has thrown various errors, most of which I’ve fixed. However, this code…

var sum = Vector3(0,0,0);
    for (n = 0; n < targets.length ; n++){   sum += targets[n].transform.position;	}        
      avgDistance = sum / targets.length;  var largestDifference = returnLargestDifference();

which gathers the various target Objects positions from an array and gives a focal point for the camera to LookAt now gives errors with the code:

theCamera.transform.position.z = avgDistance.z - distance + largestDifference;

and

 theCamera.transform.LookAt(avgDistance);

giving the errors ‘Z’ is not a member of ‘Object’ and 'ambiguous reference ‘LookAt’ respectively.
As ‘avgDistance’ is holding an objects positional data I think it’s probably a casting error but I can’t seem to figure it.
Any help ?

Sounds like avgDistance is not defined as being a Vector3, but is in stead perceived as a regular object type.

Yes, just had another go at the script with a clear head and of course, it needs a Vector3 declaration.
3.3 let me get away with it, should have seen it earlier!