trying to make my turret target the closest enemy and then rotate to face it results in error

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Turret : MonoBehaviour
{
    public Transform target;
    public float speed = 1.0f;
    void OnTriggerStay(Collider col)
    {
        target = FindClosestEnemy();
        Vector3 targetDirection = target.position - transform.position;
        float singleStep = speed * Time.deltaTime;
        Vector3 newDirection = Vector3.RotateTowards(transform.forward, targetDirection, singleStep, 0.0f);
        Debug.DrawRay(transform.position, newDirection, Color.red);
        transform.rotation = Quaternion.LookRotation(newDirection);
    }
    public GameObject FindClosestEnemy()
    {
        GameObject[] gos;
        gos = GameObject.FindGameObjectsWithTag("Human");
        GameObject closest;
        closest = null;
        float distance = Mathf.Infinity;
        Vector3 position = transform.position;
        foreach (GameObject go in gos)
        {
            Vector3 diff = go.transform.position - position;
            float curDistance = diff.sqrMagnitude;
            if (curDistance < distance)
            {
                closest = go;
                distance = curDistance;
            }
        }
        return closest;
    }
}

Turret.cs(11,18) Cannot implicitly convert type ‘UnityEngine.GameObject’ to ‘UnityEngine.Transform’
I do not understand what is wrong or how to fix this and google isnt turning up any results
theres no actual weapon for the turret yet. I am just trying to do this in smaller bite sized steps as I am not proficient in c#. This current script is trying to search for the closest player/NPC, and then it will rotate the weapon (a dish thats supposed to represent a parabolic mirror) to aim at its target

So you’re saying you don’t know the difference between a Transform component type and a GameObject type? They’re completely different things i.e. types. Square peg, round hole. :slight_smile:

It tells you Line 11, Column 18. You only then have to look at what “target” is and see you’ve defined it as a Transform. You then look at your “FindClosestEnemy()” method and see it doesn’t return a Transform but a GameObject.

my brain didnt catch this and I realized what was wrong
fixed it by changing target = FindClosestEnemy(); to target = FindClosestEnemy().transform; and it worked perfectly