Get nearest object and find direction problem

Trying to find the nearest object and then get the direction from that object to the player. Keep getting the error “‘transform’ is not a member of ‘Object’.” which I don’t understand because the object it refers to is being set to a GameObject which should have transform available to it!

function FixedUpdate() {

     if (EQ&&thrown) {
		//Objects to get direction
		var player = GameObject.Find("FPSController");
		var target = GetNearestTaggedObject();
		//Vector from target to player
		var heading = (player.transform.position - target.transform.position);
		var distance = heading.magnitude;
		var direction = heading/distance;
		//Push player away from target
		player.transform.Translate(direction * .5 * Time.deltaTime, Space.World);

function GetNearestTaggedObject() {
    var nearestDistanceSqr = Mathf.Infinity;
    var taggedGameObjects = GameObject.FindGameObjectsWithTag(searchTag); 
    var nearestObj = null;
    for (var obj : GameObject in taggedGameObjects) {
        var objectPos = obj.transform.position;
        var distanceSqr = (objectPos - transform.position).sqrMagnitude;
        if (distanceSqr < nearestDistanceSqr) {
            nearestObj = obj.transform;
            nearestDistanceSqr = distanceSqr;
    return nearestObj;

You should declare the variable types. If not mentioned, JS tries to infer the type from the value you’re using to initialize the variable - if there’s no initialization value, the variable is assumed to be Object, which can hold any type. In this particular case, the problem probably is caused by this line:

   var target = GetNearestTaggedObject();

GetNearestTaggedObject has no return type, neither the type of target is explicitly declared, thus it’s assumed to be Object. Change this line to:

   var target: Transform = GetNearestTaggedObject();

You should also declare the return type of GetNearestTaggedObject and the type of nearestObj:

   function GetNearestTaggedObject(): Transform { // declare the return type
       var nearestDistanceSqr = Mathf.Infinity;
       var taggedGameObjects = GameObject.FindGameObjectsWithTag(searchTag); 
       var nearestObj: Transform = null; // null doesn't define the type

As a rule of thumb, always declare the type of any variable that doesn’t have an initialization value. Declare also the type of variables initialized with untyped values (like nearestObj - null has no specific type).

Actually I missed that the player object is declared in the update function, but not in the other. Put line 5 where you declare your player object outside of the update function so both functions can use it and put what I mentioned in my last comment on line 27. Hope it works for you.