Parent Spawn prefab

Hi all, im trying to spawn a prefab (successful) at location “spawnpos” (Successful), but make it a child of the parent “Tokens attach” (unsuccessful) as soon as it is spawned. I think ive put the transform.position line in the wrong place maybe but im new so not sure.
here is my script:

public class Spawner : MonoBehaviour
{
    public Transform spawnPos;
    public GameObject TokenPrefab;
    public GameObject Tokensattach;

    // Update is called once per frame
   
    void Update()
    {
       
        if (Input.GetKeyDown(KeyCode.Space))
        {
            Instantiate(TokenPrefab, spawnPos.position, spawnPos.rotation);
        }

        TokenPrefab.transform.parent = Tokensattach;
    }
}

thanks

The issue is that you are referencing the prefab and not the instance of “TokenPrefab”.

Instantiate has another parameter that sets the parent of the instantiated object.

Try:

Instantiate(TokenPrefab, spawnPos.position, spawnPos.rotation, Tokensattach.transform);

Awsome thanks mate that worked!! Gotta love these forums.