Instantiate a child object?

Hello. I am trying to make it so that when I Instantiate an object, that is a child of the object that the Instantiate script is attatched to. I was told in Unity Answers to try Object.parent=transform, but when I tried to implement that into my code I get an error about a missing semi-colon, and when that is fixed more errors come about, what is wrong with my code.

var SPAWN  :GameObject;
function Start () {InvokeRepeating ("SPAWNER", 3,5);}
function SPAWNER (){ 
	transform instObj=Instantiate(SPAWN, transform.position, transform.rotation);instObj.parent = transform;
}

try instObj.transform.parent = this.transform

I am still getting the errors.

Post the errors, and post the code. Simply saying “I am still getting the errors” does not help.

instObj should be a gameobject not a transform.

GameObject instObj;

instObj.transform.parent = transform;

It is still not working

var SPAWN  :GameObject;

function Start () {
InvokeRepeating ("SPAWNER", 3,5);
}
function SPAWNER (){ 
GameObject instObj;=Instantiate(SPAWN, transform.position, transform.rotation);instObj.transform.parent = transform;
}

Errors:
(8,19): UCE0001: ‘;’ expected. Insert a semicolon at the end.
(8,19): BCE0043: Unexpected token: ;.
(8,11): UCE0001: ‘;’ expected. Insert a semicolon at the end.

the first line of spawner function is completely wrong

On line 6, get rid of the semicolon next to the equals sign.

I did that and I get this error
(8,11): UCE0001: ‘;’ expected. Insert a semicolon at the end.

Your are using Javascript with C# syntax.

GameObject instObj =

Should be:

instObj : GameObject =

I did that,

var SPAWN  :GameObject;
function Start () {
InvokeRepeating ("SPAWNER", 3,5);
}
function SPAWNER (){ 
instObj : GameObject =Instantiate(SPAWN, transform.position, transform.rotation);instObj.transform.parent = transform;
}

and I get theese errors:
(10,9): BCE0043: Unexpected token: :.
(10,10): UCE0001: ‘;’ expected. Insert a semicolon at the end.

You didn’t create the variable before, so you have to put var before it.

var instObj : GameObject = Instantiate(...);

Just tested it and it works.

Thanks