Car Enter/Exit Script Multiple Cars Problem

Hello, im quite new to unity answers and i was just hoping that someone could help me with my problem, ive been racking my brain for ages and i just cant figure it out

basicly my enter exit script works 100% fine whenever i have one single car in my scene but once i add a second (by copy and pasting the first) the second car wont disable the player but the player will still be attached to the car and the car will be controllable however the other car will always work perfectly fine. another thing i noticed is that while driving the second car i cant diable the player through the inspectors check box as it immediately becomes rechecked instantly

here is my enter/exit script (its in js):

var inTrigger = false;
var incar = false;
var player : Transform;
var exitPoint : Transform;
var Car : Transform;
function OnTriggerEnter(collider : Collider)
 {
     if(collider.tag == "Player")
     {
     	inTrigger = true;
      }}
      
function OnTriggerExit(collider : Collider)
 {
     if(collider.tag == "Player")
     {
     	inTrigger = false;
      }}
      
      
function Update(){

if(inTrigger){
	if (Input.GetKeyDown ("e"))
		incar = (!incar);
	}
if(inTrigger == false){
incar = false;
}

if(incar){

         player.gameObject.SetActive (false);
         // Parent player to ExitPoint
         player.parent = exitPoint.transform;
         player.transform.localPosition = Vector3(-0.25,0,0);
         //Parent playerParent to car
         exitPoint.parent = Car.transform;
         exitPoint.transform.localPosition = Vector3(-0.25,0,0);
         // Enable car as controllable object
         Car.GetComponent("DrivingScript").enabled = true;

}
else{


         player.gameObject.SetActive (true);
         // Unparent Player from everything.
         player.transform.parent = null;
         // Disable car as a controllable
         Car.GetComponent("DrivingScript").enabled = false;
}

}

i actually managed to figure it out and it really still confuses me but i decided to test someone else’s Enter/Exit Script and i found the problem to be with this line: incar = (!incar);

and the problem stops if you include a else function like i have done in the completed fully functional script below (btw the script below is actually another script ive found on unity answers and ive modified it if a few ways, it still follows roughly the same principle though)

 var car : Transform;
 var player : Transform;
 var exitPoint : Transform; 
 var doorTriggerLeft : Transform;
 var PlayerCamera : Camera;
 var CarCamera : Camera; 
 var isPlayerVisible : boolean;
 var driving : boolean;
 function Update()
 {
 if(driving){
 isPlayerVisible = true;
 }
 if (Input.GetKeyDown("f")&& isPlayerVisible) 
 {
 driving = !driving;
if(driving){

 player.gameObject.active = false;

 player.parent = exitPoint.transform;
 player.transform.localPosition = Vector3(0,0,0);

 exitPoint.parent = car.transform;
 exitPoint.transform.localPosition = Vector3(-0.5,0,0); 

 car.GetComponent("DrivingScript").enabled=true;
 PlayerCamera.enabled = false; 
 CarCamera.enabled = true;
 }
 else
 {
 
 player.gameObject.active = true;

 player.transform.parent = null;


 exitPoint.parent = car.transform;

 car.GetComponent("DrivingScript").enabled=false;
 PlayerCamera.enabled = true; 
 CarCamera.enabled = false; 
 }
 }
 }
 
 function OnTriggerEnter(Player : Collider)
 {
 isPlayerVisible = true;
 }
 
 function OnTriggerExit(Player : Collider)
 {
 isPlayerVisible = false;
 }

yah I have also been looking for a script that will work in ta tank and a helicopter and have found little hope. but this script seems very promising.

hay all been working on a script for a few months now its finished sadly its not free but if you are not able to get ur own one to work i thought it might help you get back on track :slight_smile:
https://forum.unity3d.com/threads/enter-exit-vehicle-networked-photon-cars-planes-offline-online-easy-to-use.436698/