local function E()local E=196.2 local e=Workspace.Gravity local Z=e/E ActualDrivingTorque=VehicleParameters.DrivingTorque*Z ActualBrakingTorque=VehicleParameters.BrakingTorque*Z ActualStrutSpringStiffnessFront=VehicleParameters.StrutSpringStiffnessFront*Z ActualStrutSpringDampingFront=VehicleParameters.StrutSpringDampingFront*math.sqrt(Z)ActualStrutSpringStiffnessRear=VehicleParameters.StrutSpringStiffnessRear*Z ActualStrutSpringDampingRear=VehicleParameters.StrutSpringDampingRear*math.sqrt(Z)ActualTorsionSpringStiffness=VehicleParameters.TorsionSpringStiffness*Z ActualTorsionSpringDamping=VehicleParameters.TorsionSpringDamping*math.sqrt(Z)end local function e()for E,e in pairs(VehicleParameters)do local Z=VehicleConfig:FindFirstChild(E)if Z then if E=="\077\097\120\083\112\101\101\100"or E=="\082\101\118\101\114\115\101\083\112\101\101\100"then VehicleParameters[E]=Z.Value/mphConversion else VehicleParameters[E]=Z.Value end end end end local Z if VehicleConfig then e()Z={}local B=VehicleConfig:GetChildren()for e=1,#B,1 do Z[B[e].Name]=B[e].Changed:connect(function(Z)VehicleParameters[B[e].Name]=Z if DoGravityAdjust then E()end if Chassis then Chassis.InitializeDrivingValues()end end)end end if DoGravityAdjust then E()end workspace.Changed:Connect(function(e)if e=="\071\114\097\118\105\116\121"then if DoGravityAdjust then E()end if Chassis then Chassis.InitializeDrivingValues()end end end)local B local J local T
-- Adjust torque and springs based on gravity to keep the car drivable
local function gravityAdjust()
	local defaultGravity = 196.2
	local actualGravity = Workspace.Gravity
	local gravityChange = actualGravity / defaultGravity
	-- Speed is adjusted so that the height of jumps is preserved
	-- So maxSpeed is scaled proportionally to the sqrt of gravity
	ActualDrivingTorque = VehicleParameters.DrivingTorque * gravityChange
	ActualBrakingTorque = VehicleParameters.BrakingTorque * gravityChange

	ActualStrutSpringStiffnessFront = VehicleParameters.StrutSpringStiffnessFront * gravityChange
	ActualStrutSpringDampingFront = VehicleParameters.StrutSpringDampingFront * math.sqrt(gravityChange)
	ActualStrutSpringStiffnessRear = VehicleParameters.StrutSpringStiffnessRear * gravityChange
	ActualStrutSpringDampingRear = VehicleParameters.StrutSpringDampingRear * math.sqrt(gravityChange)

	ActualTorsionSpringStiffness = VehicleParameters.TorsionSpringStiffness * gravityChange
	ActualTorsionSpringDamping = VehicleParameters.TorsionSpringDamping * math.sqrt(gravityChange)
end

local function updateFromConfiguration()
	for property, value in pairs(VehicleParameters) do
		local configProp = VehicleConfig:FindFirstChild(property)
		if configProp then
			if property == "MaxSpeed" or property == "ReverseSpeed" then
				VehicleParameters[property] = configProp.Value / mphConversion -- convert to studs/sec
			else
				VehicleParameters[property] = configProp.Value
			end
		end
	end
end

local updateEvents
if VehicleConfig then
	updateFromConfiguration()

	updateEvents = {}
	local props = VehicleConfig:GetChildren()
	for i = 1, #props do
		updateEvents[props[i].Name] = props[i].Changed:connect(function(value)
			VehicleParameters[props[i].Name] = value
			if DoGravityAdjust then
				gravityAdjust()
			end
			if Chassis then
				Chassis.InitializeDrivingValues() -- reinitialize chassis so that changes are reflected in the rig
			end
		end)
	end
end

if DoGravityAdjust then
	gravityAdjust()
end

workspace.Changed:Connect(function(prop)
	if prop == "Gravity" then
		if DoGravityAdjust then
			gravityAdjust()
		end
		if Chassis then
			Chassis.InitializeDrivingValues() -- reinitialize chassis so that changes are reflected in the rig
		end
	end
end)

local Motors
local SteeringPrismatic
local RedressMount
