Parenting trigger moving platform

I want to have a player move with a platform whenever the player is on it. I have this script which works when the player jumps on the platform but not when he leaves.

My script is below. I don’t know why is isn’t working as it works with booleans but just not transforms!

var platform : Transform;
var player : Transform;


function OnTriggerEnter()
{
	if(player.tag == "Player1")
	{
			
		player.transform.parent = platform.transform;	
	}
}

function OnTriggerExit()
{
	if(player.tag == "Player1")
	{
		player.transform.parent = null;				
	}
}

I want to increase this to four players but it doesn’t even work for one… Any help would be great.

Cheers, Peter

You should change this script a little, and attach it to the trigger object; the trigger object, in turn, must be childed to the platform.

function OnTriggerEnter(col: Collider)
{
    if(col.tag == "Player")
    {
       col.transform.parent = transform.parent; 
    }
}

function OnTriggerExit(col: Collider)
{
    if(col.tag == "Player")
    {
       col.transform.parent = null; 
    }
}

When any character tagged “Player” enters the trigger volume, this script childs the character to the platform (the trigger’s parent). When the character exits the trigger, the parenthood is broken. This will work for any number of players, provided that all of them have the same tag “Player”.