How do i make player position relative to a object?

i have these objects a player and a vehicle. I want the player to move with the vehicle so it looks like its riding it this is the code i have for it now.

using UnityEngine;
using System.Collections;

public class transport : MonoBehaviour {

    public GameObject[] ObjectsTo;

    public GameObject[] PlayersOn;
    public Vector3[] PlayerPosition;

    void Start () {
  
    }

    void Update () {
        for (int i = 0; i < PlayersOn.Length; i++) {
            PlayerPosition[i] = this.transform.localPosition;
            //PlayerPosition[i].y = 0;

            PlayersOn[i].transform.localPosition = PlayerPosition[i] - PlayersOn [i].transform.localPosition;
        }
        for (int i = 0; i < ObjectsTo.Length; i++) {
            ObjectsTo [i].transform.position = this.transform.position;
        }

    }
}

but all this does it make the player teleport around the place like crazy.

Try

 void Update(){

 for (int i = 0; i < PlayersOn.Length; i++) {
             PlayerPosition[i].transform.position = transform.position;
        }
 }

This will let you have multiple seats, the seat at 0 being the drivers seat.
Using transform.SetParent you can make an object a child of another then the engine will handle the position for you.

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class Transport : MonoBehaviour {
    [System.Serializable]
    public struct Seat{
        public Transform seatLoc;
        public GameObject occupier;
    }

    public List<Seat> seats;

    void Start(){
        for(int i = 0; i < seats.Count; i++){
            EnterVehicle(seats[i].occupier, i);
        }
    }

    bool EnterVehicle(GameObject obj, int seatIdx){
        if(seats.Count <= 0 && seats.Count > seatIdx){
            return false;
        }

        if(seats[seatIdx].occupier != obj || !obj){
            return false;
        }

        obj.transform.position = seats[seatIdx].seatLoc.position;
        obj.transform.SetParent (transform);
        Seat curSeat = seats[seatIdx];
        curSeat.occupier = obj;
        seats[seatIdx] = curSeat;

        return true;
    }

    bool ExitVehicle(int seatIdx){
        if(seats.Count <= 0 && seats.Count > seatIdx){
            return false;
        }

        if(!seats[seatIdx].occupier){
            return false;
        }

        Seat curSeat = seats[seatIdx];
        curSeat.occupier = null;
        seats[seatIdx] = curSeat;

        return true;
    }

    GameObject GetDriver(){
        if(seats.Count > 0){
            return seats[0].occupier;
        }

        return null;
    }
}

The easiest thing, which doesn’t even require any code, is to parent the player GameObject to the vehicle GameObject. Click and drag one on top of the other and it will inherit the top-most GameObjects Transform, thereby following it by default.