Help with entering and exiting vehicle script?

Being not very good at scripting, I have come up with a basic script for entering and exiting a car, after a really long time of searching for one.

Entering car:

var instructions : GUIText;

var FPSplayer : Transform;

var car : Transform; 

var CarReplacement : Transform;
var RepSound : AudioClip;

function Start () {
	instructions.enabled = false;
}

function OnTriggerStay (col : Collider) {

	if (Input.GetKeyUp("e")) {
		FPSplayer.parent = car;

		FPSplayer.active = false;
		
		gameObject.active = false;
		
		car.parent = CarReplacement;
	
		// Play a replacement audio clip
		if (RepSound)
			AudioSource.PlayClipAtPoint(RepSound, transform.position);

		// Replace ourselves with the controllable car
		if (CarReplacement) {
			var replacement : Transform = Instantiate(CarReplacement, transform.position, transform.rotation);
		
			// Copy position  rotation from the old hierarchy into the dead replacement
			CopyTransformsRecurse(transform, replacement);
	}
	instructions.enabled = true;	
}
}

function OnTriggerExit () {
	instructions.enabled = false;
}

static function CopyTransformsRecurse (src : Transform,  dst : Transform) {
	dst.position = src.position;
	dst.rotation = src.rotation;
	
	for (var child : Transform in dst) {
		// Match the transform with the same name
		var curSrc = src.Find(child.name);
		if (curSrc)
			CopyTransformsRecurse(curSrc, child);
	}
}

Exiting car:

var instructions : GUIText;

var FPSplayer : Transform;

var car : Transform; 

var CarReplacement : Transform;
var RepSound : AudioClip;

function Start () {
	instructions.enabled = false;
}

function OnTriggerStay (FPSplayer) {

	if (Input.GetKeyUp("e")) {
		FPSplayer.parent = null;

		FPSplayer.active = true;
		
		Destroy(gameObject);
	
		// Play a replacement audio clip
		if (RepSound)
			AudioSource.PlayClipAtPoint(RepSound, transform.position);

		// Replace ourselves with the controllable car
		if (CarReplacement) {
			var replacement : Transform = Instantiate(CarReplacement, transform.position, transform.rotation);
		
			// Copy position  rotation from the old hierarchy into the dead replacement
			CopyTransformsRecurse(transform, replacement);
	}
	instructions.enabled = true;
}
}

function OnTriggerExit () {
	instructions.enabled = false;
}

static function CopyTransformsRecurse (src : Transform,  dst : Transform) {
	dst.position = src.position;
	dst.rotation = src.rotation;
	
	for (var child : Transform in dst) {
		// Match the transform with the same name
		var curSrc = src.Find(child.name);
		if (curSrc)
			CopyTransformsRecurse(curSrc, child);
	}
}

Here’s how it’s supposed to work: I go next to the car (where the trigger is) then the first person controller is disabled (and the is put as the child of the controllable car), the car is deleted, and then the controllable car is spawned in the same position so that you can drive around.
The get out car script will re-enable the firstperson player, delete the controllable car, and spawn a non-controllable car, so that you can walk around in first person again.

Here are the problems:
-It’s supposed to only work when the player stays in the trigger AND THEN PRESSES E. But instead it works WHENEVER the player presses E :frowning:

-Instructions are not enabled when the player enters the trigger :frowning:

-I am pretty sure that the get out car script does not work, but I am still trying!

-The enter script disables the car, but not it’s children???

-Also, how do I make it where an OnTriggerEnter only reacts when a certain gameObject enters it?

P.S., the enter script is attached to the car, and the exit script is attached to the controllable car.

If anyone can help in any way, Thanks.

Just to address one of your questions:

You can use tags for this. (That is, in the OnTriggerEnter() function, only proceed if the game object has the right tag.)

Thanks! ok, I am pretty sure I know how to use that, but where exactly do I put it within the OnTriggerEnter()?
Do I put it in the parentheses?

Nevermind, the tagging works, and I can get into the car when staying in the trigger! Thanks!

I am having a new problem. I have a prefab, and I want one of it’s variables to be an object in the hierarchy, but it will only let me set the variable to a prefab. I need it to be an object in the hierarchy because it will change parents and Unity will not let me change the parent of a prefab.