Simple car entering and exit script? for an object

Ok so i have a car object thats called dpv and all i want it to do is when the “player” object is near the dpv and press’s tab it enters the car and pressing tab again exits. this car has no animations no wheels just 1 object

//Put this before Update
bool inCar=false;
public GameObject car;
//Only if the script isn't on the player
public GameObject player;

//Put this in Update
if(Input.GetKeyDown(Keycode.Tab)){
    if(Vector3.distance(playerpos,carpos)<=maxdistance && !inCar){
        player.transform.postion=car.transform.position;
        player.transform.setParent(car.transform);
        inCar=true;
    } else if(inCar){
        player.transform.parent=null;
        inCar=false;
    }
}

Also, you may want to set the player’s position above/next to the car after the parent is cleared to keep collisions working, and you should probably do just transform.position instead of player.transform.position, unless this script isn’t located on the player.

That should work?