local function Z()local Z=196.2 local q=Workspace.Gravity local C=q/Z ActualDrivingTorque=VehicleParameters.DrivingTorque*C ActualBrakingTorque=VehicleParameters.BrakingTorque*C ActualStrutSpringStiffnessFront=VehicleParameters.StrutSpringStiffnessFront*C ActualStrutSpringDampingFront=VehicleParameters.StrutSpringDampingFront*math.sqrt(C)ActualStrutSpringStiffnessRear=VehicleParameters.StrutSpringStiffnessRear*C ActualStrutSpringDampingRear=VehicleParameters.StrutSpringDampingRear*math.sqrt(C)ActualTorsionSpringStiffness=VehicleParameters.TorsionSpringStiffness*C ActualTorsionSpringDamping=VehicleParameters.TorsionSpringDamping*math.sqrt(C)end local function q(Z,q)if Z=="\077\097\120\083\112\101\101\100"or Z=="\082\101\118\101\114\115\101\083\112\101\101\100"then return q/mphConversion end return q end local C=nil local function A()local A=script.Parent.Parent for Z,C in pairs(VehicleParameters)do local G=A:GetAttribute(Z)if G then VehicleParameters[Z]=q(Z,G)end end C=A.AttributeChanged:Connect(function(C)if VehicleParameters[C]==nil then return end local G=A:GetAttribute(C)VehicleParameters[C]=q(C,G)if DoGravityAdjust then Z()end if Chassis then Chassis.InitializeDrivingValues()end end)end A()if DoGravityAdjust then Z()end workspace.Changed:Connect(function(q)if q=="\071\114\097\118\105\116\121"then if DoGravityAdjust then Z()end if Chassis then Chassis.InitializeDrivingValues()end end end)local G local k local u
-- 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 convertProperty(property, value)
	if property == "MaxSpeed" or property == "ReverseSpeed" then
		-- convert to studs/sec
		return value / mphConversion
	end

	return value
end

local changedAttributesConnection = nil
local function updateFromConfiguration()
	local obj = script.Parent.Parent

	for property, value in pairs(VehicleParameters) do
		local configProp = obj:GetAttribute(property)

		if configProp then
			VehicleParameters[property] = convertProperty(property, configProp)
		end
	end

	-- Handle dynamic changes
	changedAttributesConnection = obj.AttributeChanged:Connect(function(property)
		-- Only handle attributes we're interested in
		if VehicleParameters[property] == nil then
			return
		end

		local value = obj:GetAttribute(property)
		VehicleParameters[property] = convertProperty(property, value)

		if DoGravityAdjust then
			gravityAdjust()
		end

		if Chassis then
			Chassis.InitializeDrivingValues() -- reinitialize chassis so that changes are reflected in the rig
		end
	end)
end

updateFromConfiguration()

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
