Help my code keeps saying Cannot implicitly convert type 'UnityEngine.GameObject' to 'UnityEngine.GameObject[]' I'm rather new to coding and i just can't figure it out here's the code

public class PlayerSpawnController : MonoBehaviour

{
public GameObject playerSpawnArray; //This is our playerspawn variable, it is an array. An Array is a list.
private int randNum;

void Awake()
{	
	playerSpawnArray = GameObject.FindGameObjectWithTag("PlayerSpawn");
}
// Use this for initialization
void Start () 
{

}

// Update is called once per frame
void Update () 
{

}

public GameObject GetRandomPlayerSpawn(int randNum)
{
	randNum = Random.Range(0, (playerSpawnArray.Length));
	
	if (playerSpawnArray.Length > 0)
	{
		return playerSpawnArray[randNum];
	}
	else 
	{
		return null;
	}
}

}

This:

GameObject.FindGameObjectWithTag("PlayerSpawn")

is going to return a single GameObject… which you are trying to assign to a variable of type GameObject. That’s not kosher.

Actually, I don’t see FindGameObjectWithTag in the documentation… Unity - Scripting API: GameObject

flaviusxvii summarizes your issue well.

In you Awake() function, you specify playerSpawnArray as a single GameObject.

> if (playerSpawnArray.Length > 0)
> {
>     return playerSpawnArray[randNum];
> }

In the statement above, you use playerSpawnArray as an Array of GameObjects.

‘UnityEngine.GameObject’ to ‘UnityEngine.GameObject[]’

In essence, Unity is letting you know that you cannot use a single GameObject as if it were an Array of GameObjects.

Happy Coding =)