Cannot show self as parent to newly instantiated object

I know this is the simplest of tasks. But I’m really confused here. I’m instantiating the object and trying to assign its parent as self (the empty gameobject script is written onto). Tried the following:

var robot = Instantiate(robots[0]) as GameObject;
robot.transform.parent = transform;

it didn’t work so I tried:

public Transform self;

var robot = Instantiate(robots[0]) as GameObject;
robot.transform.parent = self.transform;

This didn’t work either. I tried assigning self to another gameobject too. GameObject is instantiated as expected but parentless. Console is throwing “Null Object Reference” error. I’m really frustrated over here. Please help.

have you tried: `this.gameObject.transform

I helped another gentleman here with a similar issue:

Hope it helps, remember to mark as answered if it does.
`

Ok, I found a solution at last. I just put

transform.parent = GameObject.Find("minions").transform;

into the prefab’s own script. It works now. I still don’t get why previous solutions didn’t work though.