Car falls over when the car turns left & right??

I’m created a kart game and have a kart movement script but I’m having a problem with it when I turn the kart left and right its tips overs and then when i move again it just falls over. i cant seem to work out what iv done wrong

using System.Collections;
using UnityEngine;
public class Car : MonoBehaviour
{
     public float maxTorque = 5000f;
     public float speed;
     public Transform centerofMass;
     public WheelCollider[] wheelColliders = new WheelCollider[4];
     public Transform[] tireMeshes = new Transform[4];
     private Rigidbody m_rigidBody;
     void Start()
     {
         m_rigidBody = GetComponent<Rigidbody>();
         m_rigidBody.centerOfMass = centerofMass.localPosition;
     }
     void Update()
     {
         UpdateMeshesPositions();
     }
     void FixedUpdate()
     {
         float steer = Input.GetAxis ("Horizontal");
         float accelrate = Input.GetAxis ("Vertical");
         float finalAngle = steer * 45f;
         wheelColliders [0].steerAngle = finalAngle;
         wheelColliders [1].steerAngle = finalAngle;
         for (int i = 0; i < 4; i++)
         {
             wheelColliders_.motorTorque = accelrate * maxTorque;_

}
}
void UpdateMeshesPositions()
{
for(int i = 0; i < 4; i++)
{
Quaternion quat;
Vector3 pos;
wheelColliders*.GetWorldPose(out pos, out quat);*
tireMeshes*.position = pos;*
tireMeshes*.rotation = quat;*
}
}
}

try puting a rotation constraint to the rigidbody of the gameobject

You could put a rotation constraint on your vehicle as @a161803398874 mentioned but this would limit some functionality of your vehicle. What you may want to do instead is implement some form of anti roll script. Here is something I wrote just recently. It is simple but seems to do the job pretty well.

var antiRollStrength : int = 1000;//How intense the anti roll force is.

function Update()
{
    var rigidBodyPhysics = GetComponent.<Rigidbody>();
	AntiSway(tire);//Put your tire game objects in here.
}

function AntiSway(tire:GameObject)
{
	var hit : WheelHit;
	if(!tire.GetComponent.<WheelCollider>().GetGroundHit(hit))//If a tire leaves the ground
	{
		rigidBodyPhysics.AddForceAtPosition(-gameObject.transform.up * antiRollStrength, tire.gameObject.transform.position);//Apply a downward force at the location of that tire.
	}
}

This script simply checks if the tire is off the ground. If the tire is off the ground the script applies a downward force to that location in an attempt to re - ground the tire.

NOTE: setting “antiRollStrength” too high will result in an unstable vehicle while setting it too low will not be enough to properly re - ground the tire. It is important to test the waters here and find the right value for your vehicle. I also recommend taking a look at your vehicle’s tires’ friction, stiffness, suspension values etc.