How to parent a Transform through JavaScript?

So, I am making a game that you need to pick up a pillow and be able to use it for a limited number of times. I’m am sort of new to Unity. I have almost everything down in my checklist for this script, except I can’t make it to where it instantiates in front of you parented to the First Person Controller so I can move around with it as I please.

So in summary I have:

  • Able to destroy the object from a OnTriggerEnter
  • Add it to a temporary inventory
  • Able to use it a limited number of times to where it destroys, consumable.

What I need help with:

  • How to attach the Pillow to the Player so it’s like holding an item.

Here’s my code:
//playpar is the parent basically
var playpar : Transform;
var Pillow : Transform;
//pillowLocation is where it will spawn
var pillowLocation : Transform;
var pillowLimit : int = 0;
var pillowUses : int = 75;

function Update () {
		if(pillowUses == -1){
			pillowUses = 0;
//Here is where I tried and parent the object
function GrabPillow (){

	var grabbed = Instantiate(Pillow, pillowLocation.position, pillowLocation.rotation);
	Pillow.transform.parent = playpar.transform;

function OnTriggerEnter (grab : Collider){
	if(grab.gameObject.tag == "weapon"){
		if(pillowLimit == 2){
			pillowLimit = 1;
//Consumed function is a work in Progress
function Consumed (){

	if(pillowUses == 0){


I want to learn as much as I can so explain if you can :slight_smile:
Thank you.

ChildObject.transform.parent = ParentObject.transform;