--print(speed/1.298)
--print(carSeat.Parent.Parent.Wheels.FL.Wheel.RotVelocity.Magnitude)
	
	--print("Speed: "..speed)
	--print("Wheels: "..math.abs(orderch))
	
if carSeat.Storage.Automatic.Value == true and currentgear.Value > 2 and script.Parent.Active.CC.Value == false then --hpatt cant be automatic
if rpm.Value <= redline.Value*0.2 and currentgear.Value > 3 then
	script.Parent.Functions.ShiftDownRequested.Value = true 
	
elseif rpm.Value >= redline.Value*0.9*mode and script.Parent.Storage.Throttle.Throttle.Value > 0.1 and currentgear.Value ~= script.Parent.Storage.AmountOfGears.Value +2 and shf == true then 
	script.Parent.Functions.ShiftUpRequested.Value = true
	
elseif x1x*trans.Value <= redline.Value*0.8*mode and x1x*trans.Value < redline.Value*0.9*mode and currentgear.Value > 3 and script.Parent.Storage.Throttle.Throttle.Value > 0.6 then
	if currentgear.Value > 3 then
	script.Parent.Functions.ShiftDownRequested.Value = true 
	end
	
end
end

if currentgear.Value == 1 then
	park = 0
else
	park = 1
end

if carSeat.Throttle ~= -1 and carSeat.Storage.Handbrake.Value ~= true then
if script.Parent.Functions.ShiftDownRequested.Value ~= true and script.Parent.Functions.ShiftUpRequested.Value ~= true then
	if rpm.Value > redline.Value then else
		FL.MotorMaxAcceleration = 10+(((0.001*(m*2))*rpm.Value)+((46*m)*convert)*(low*6.5))*four*throttle.Value
		FR.MotorMaxAcceleration = 10+(((0.001*(m*2))*rpm.Value)+((46*m)*convert)*(low*6.5))*four*throttle.Value
		RL.MotorMaxAcceleration = 10+(((0.001*(m*2))*rpm.Value)+((46*m)*convert)*(low*6.5))*four*throttle.Value
		RR.MotorMaxAcceleration = 10+(((0.001*(m*2))*rpm.Value)+((46*m)*convert)*(low*6.5))*four*throttle.Value
	end
	
		if currentgear.Value ~= 1 and carSeat.Throttle ~= -1 then
	if throttle.Value ~= 0 then
if script.Parent.Storage.EngineType.Value == "Petrol" then tL = (0.45*vt)*TC
	if rpm.Value < 2000*convert then 
		FL.MotorMaxTorque = b*((((((rpm.Value * (1.035*((xans/1.4)/900)))*(1-(torquesplit.Value/100))*throttle.Value*CT)*(hp.Value/70))*mid*ft)*ovo*checkcluch)/ch)*tL*xi
		FR.MotorMaxTorque = b*((((((rpm.Value * (1.035*((xans/1.4)/900)))*(1-(torquesplit.Value/100))*throttle.Value*CT)*(hp.Value/70))*mid*ft)*ovo*checkcluch)/ch)*tL*xi
		RL.MotorMaxTorque = b*((((((rpm.Value * (1.035*((xans/1.4)/900)))*((torquesplit.Value/100))*throttle.Value*CT)*(hp.Value/70))*mid*rt)*ovo*checkcluch)/ch)*tL*xi
		RR.MotorMaxTorque = b*((((((rpm.Value * (1.035*((xans/1.4)/900)))*((torquesplit.Value/100))*throttle.Value*CT)*(hp.Value/70))*mid*rt)*ovo*checkcluch)/ch)*tL *xi
		FL.AngularVelocity = 2500*clutch.Clutch.Value*direction*park
		FR.AngularVelocity = 2500*clutch.Clutch.Value*direction*park
		RL.AngularVelocity = 2500*clutch.Clutch.Value*direction*park
		RR.AngularVelocity = 2500*clutch.Clutch.Value*direction*park
	end
	
	if rpm.Value > 2000*convert and rpm.Value < 6000*convert then
		FL.MotorMaxTorque = b*(((((rpm.Value * (0.488*((xans/1.4)/900)))+2000)*(1-(torquesplit.Value/100))*throttle.Value*CT)*(hp.Value/70)*mid*ft)*ovo*checkcluch)*tL*xi script.lp.Value = false
		FR.MotorMaxTorque = b*(((((rpm.Value * (0.488*((xans/1.4)/900)))+2000)*(1-(torquesplit.Value/100))*throttle.Value*CT)*(hp.Value/70)*mid*ft)*ovo*checkcluch)*tL*xi
		RL.MotorMaxTorque = b*(((((rpm.Value * (0.488*((xans/1.4)/900)))+2000)*((torquesplit.Value/100))*throttle.Value*CT)*(hp.Value/70)*mid*rt)*ovo*checkcluch)*tL*xi
		RR.MotorMaxTorque = b*(((((rpm.Value * (0.488*((xans/1.4)/900)))+2000)*((torquesplit.Value/100))*throttle.Value*CT)*(hp.Value/70)*mid*rt)*ovo*checkcluch)*tL *xi
		FL.AngularVelocity = 2500*clutch.Clutch.Value*direction*park
		FR.AngularVelocity = 2500*clutch.Clutch.Value*direction*park
		RL.AngularVelocity = 2500*clutch.Clutch.Value*direction*park script.lp.Value = true
		RR.AngularVelocity = 2500*clutch.Clutch.Value*direction*park
	end
	
	if rpm.Value > 6000*convert then 
		FL.MotorMaxTorque = b*(((((rpm.Value * (-0.214*((xans/1.4)/900)))+6000)*(1-(torquesplit.Value/100))*throttle.Value*CT)*(hp.Value/70)*mid*ft)*checkcluch)*tL*xi
		FR.MotorMaxTorque = b*(((((rpm.Value * (-0.214*((xans/1.4)/900)))+6000)*(1-(torquesplit.Value/100))*throttle.Value*CT)*(hp.Value/70)*mid*ft)*checkcluch)*tL*xi
		RL.MotorMaxTorque = b*(((((rpm.Value * (-0.214*((xans/1.4)/900)))+6000)*((torquesplit.Value/100))*throttle.Value*CT)*(hp.Value/70)*mid*rt)*checkcluch)*tL*xi
		RR.MotorMaxTorque = b*(((((rpm.Value * (-0.214*((xans/1.4)/900)))+6000)*((torquesplit.Value/100))*throttle.Value*CT)*(hp.Value/70)*mid*rt)*checkcluch)*tL *xi
		FL.AngularVelocity = 2500*clutch.Clutch.Value*direction*park
		FR.AngularVelocity = 2500*clutch.Clutch.Value*direction*park
		RL.AngularVelocity = 2500*clutch.Clutch.Value*direction*park
		RR.AngularVelocity = 2500*clutch.Clutch.Value*direction*park
	end
	
	if rpm.Value > redline.Value then 
		FL.MotorMaxAcceleration = ((((120/(convert*7000))*rpm.Value)*(hp.Value/70)*conf)+25)*5
		FR.MotorMaxAcceleration = ((((120/(convert*7000))*rpm.Value)*(hp.Value/70)*conf)+25)*5
		RL.MotorMaxAcceleration = ((((120/(convert*7000))*rpm.Value)*(hp.Value/70)*conf)+25)*5
		RR.MotorMaxAcceleration = ((((120/(convert*7000))*rpm.Value)*(hp.Value/70)*conf)+25)*5
		FL.AngularVelocity = 0
		FR.AngularVelocity = 0
		RL.AngularVelocity = 0
		RR.AngularVelocity = 0
		FL.MotorMaxTorque = (((((rpm.Value * (-0.214*((2000/1.4)/900)))+6000)*(1-(torquesplit.Value/100))*1*CT)*(hp.Value/70)*mid*ft)*ovo+xt)*2
		FR.MotorMaxTorque = (((((rpm.Value * (-0.214*((2000/1.4)/900)))+6000)*(1-(torquesplit.Value/100))*1*CT)*(hp.Value/70)*mid*ft)*ovo+xt)*2
		RL.MotorMaxTorque = (((((rpm.Value * (-0.214*((2000/1.4)/900)))+6000)*((torquesplit.Value/100))*1*CT)*(hp.Value/70)*mid*rt)*ovo+xt)*2
		RR.MotorMaxTorque = (((((rpm.Value * (-0.214*((2000/1.4)/900)))+6000)*((torquesplit.Value/100))*1*CT)*(hp.Value/70)*mid*rt)*ovo+xt)*2
	end
end

if script.Parent.Storage.EngineType.Value == "Diesel" then tL = (0.475*vt)*TC
	if rpm.Value < 2000*convert then
		FL.MotorMaxTorque = b*(((((rpm.Value * (1.679*((xans/1.4)/900)))*(1-(torquesplit.Value/100))*throttle.Value*CT)*(hp.Value/70)*mid*ft)*ovo)/ch)*tL*xi
		FR.MotorMaxTorque = b*(((((rpm.Value * (1.679*((xans/1.4)/900)))*(1-(torquesplit.Value/100))*throttle.Value*CT)*(hp.Value/70)*mid*ft)*ovo)/ch)*tL*xi
		RL.MotorMaxTorque = b*(((((rpm.Value * (1.679*((xans/1.4)/900)))*((torquesplit.Value/100))*throttle.Value*CT)*(hp.Value/70)*mid*rt)*ovo)/ch)*tL*xi
		RR.MotorMaxTorque = b*(((((rpm.Value * (1.679*((xans/1.4)/900)))*((torquesplit.Value/100))*throttle.Value*CT)*(hp.Value/70)*mid*rt)*ovo)/ch)*tL*xi
		FL.AngularVelocity = 2500*clutch.Clutch.Value*direction*park
		FR.AngularVelocity = 2500*clutch.Clutch.Value*direction*park
		RL.AngularVelocity = 2500*clutch.Clutch.Value*direction*park
		RR.AngularVelocity = 2500*clutch.Clutch.Value*direction*park
	end
	
	if rpm.Value > 2000*convert and rpm.Value < 4500*convert then
		FL.MotorMaxTorque = b*(((((rpm.Value * (0.880*((xans/1.4)/900)))+2000)*(1-(torquesplit.Value/100))*throttle.Value*CT)*(hp.Value/70)*mid*ft)*ovo)*tL*xi
		FR.MotorMaxTorque = b*(((((rpm.Value * (0.880*((xans/1.4)/900)))+2000)*(1-(torquesplit.Value/100))*throttle.Value*CT)*(hp.Value/70)*mid*ft)*ovo)*tL*xi
		RL.MotorMaxTorque = b*(((((rpm.Value * (0.880*((xans/1.4)/900)))+2000)*((torquesplit.Value/100))*throttle.Value*CT)*(hp.Value/70)*mid*rt)*ovo)*tL*xi
		RR.MotorMaxTorque = b*(((((rpm.Value * (0.880*((xans/1.4)/900)))+2000)*((torquesplit.Value/100))*throttle.Value*CT)*(hp.Value/70)*mid*rt)*ovo)*tL*xi
		FL.AngularVelocity = 2500*clutch.Clutch.Value*direction*park
		FR.AngularVelocity = 2500*clutch.Clutch.Value*direction*park
		RL.AngularVelocity = 2500*clutch.Clutch.Value*direction*park
		RR.AngularVelocity = 2500*clutch.Clutch.Value*direction*park
	end
	
	if rpm.Value > 4500*convert then
		FL.MotorMaxTorque = b*(((((rpm.Value * (-0.204*((xans/1.4)/900)))+4500)*(1-(torquesplit.Value/100))*throttle.Value*CT)*(hp.Value/70)*mid*ft)*ovo)*tL*xi
		FR.MotorMaxTorque = b*(((((rpm.Value * (-0.204*((xans/1.4)/900)))+4600)*(1-(torquesplit.Value/100))*throttle.Value*CT)*(hp.Value/70)*mid*ft)*ovo)*tL*xi
		RL.MotorMaxTorque = b*(((((rpm.Value * (-0.204*((xans/1.4)/900)))+4500)*((torquesplit.Value/100))*throttle.Value*CT)*(hp.Value/70)*mid*rt)*ovo)*tL*xi
		RR.MotorMaxTorque = b*(((((rpm.Value * (-0.204*((xans/1.4)/900)))+4500)*((torquesplit.Value/100))*throttle.Value*CT)*(hp.Value/70)*mid*rt)*ovo)*tL*xi
		FL.AngularVelocity = 2500*clutch.Clutch.Value*direction*park
		FR.AngularVelocity = 2500*clutch.Clutch.Value*direction*park
		RL.AngularVelocity = 2500*clutch.Clutch.Value*direction*park
		RR.AngularVelocity = 2500*clutch.Clutch.Value*direction*park
	end
	
	if rpm.Value > redline.Value then
		FL.MotorMaxAcceleration = ((((120/(convert*7000))*rpm.Value)*(hp.Value/70)*conf)+25)*5
		FR.MotorMaxAcceleration = ((((120/(convert*7000))*rpm.Value)*(hp.Value/70)*conf)+25)*5
		RL.MotorMaxAcceleration = ((((120/(convert*7000))*rpm.Value)*(hp.Value/70)*conf)+25)*5
		RR.MotorMaxAcceleration = ((((120/(convert*7000))*rpm.Value)*(hp.Value/70)*conf)+25)*5
		FL.AngularVelocity = 0
		FR.AngularVelocity = 0
		RL.AngularVelocity = 0
		RR.AngularVelocity = 0
		FL.MotorMaxTorque = (((((rpm.Value * (-0.214*((2000/1.4)/900)))+6000)*(1-(torquesplit.Value/100))*1*CT)*(hp.Value/70)*mid*ft)*ovo+xt)*2
		FR.MotorMaxTorque = (((((rpm.Value * (-0.214*((2000/1.4)/900)))+6000)*(1-(torquesplit.Value/100))*1*CT)*(hp.Value/70)*mid*ft)*ovo+xt)*2
		RL.MotorMaxTorque = (((((rpm.Value * (-0.214*((2000/1.4)/900)))+6000)*((torquesplit.Value/100))*1*CT)*(hp.Value/70)*mid*rt)*ovo+xt)*2
		RR.MotorMaxTorque = (((((rpm.Value * (-0.214*((2000/1.4)/900)))+6000)*((torquesplit.Value/100))*1*CT)*(hp.Value/70)*mid*rt)*ovo+xt)*2
	end
end

if script.Parent.Storage.EngineType.Value == "Electric" then
		FL.MotorMaxTorque = b*(((((rpm.Value * (-0.04*((xans/1.4)/900)))+2000)*(1-(torquesplit.Value/100))*throttle.Value*CT)*(hp.Value/70)*mid*ft)*ovo)*tL*xi
		FR.MotorMaxTorque = b*(((((rpm.Value * (-0.04*((xans/1.4)/900)))+2000)*(1-(torquesplit.Value/100))*throttle.Value*CT)*(hp.Value/70)*mid*ft)*ovo)*tL*xi
		RL.MotorMaxTorque = b*(((((rpm.Value * (-0.04*((xans/1.4)/900)))+2000)*((torquesplit.Value/100))*throttle.Value*CT)*(hp.Value/70)*mid*rt)*ovo)*tL*xi
		RR.MotorMaxTorque = b*(((((rpm.Value * (-0.04*((xans/1.4)/900)))+2000)*((torquesplit.Value/100))*throttle.Value*CT)*(hp.Value/70)*mid*rt)*ovo)*tL*xi
		FL.AngularVelocity = 2500*direction*park
		FR.AngularVelocity = 2500*direction*park
		RL.AngularVelocity = 2500*direction*park
		RR.AngularVelocity = 2500*direction*park
		

	end 
	else 
		
		if carSeat.Throttle ~= -1 and carSeat.Storage.Handbrake.Value ~= true then
		--guava = (redline.Value/1000)-(rpm.Value/1000)
		FL.MotorMaxTorque = 200 * (displacement.Value/2000)*clutch.Clutch.Value*(1-script.Parent.Storage.Brake.Value)*(1-(torquesplit.Value/100))
		FR.MotorMaxTorque = 200 * (displacement.Value/2000)*clutch.Clutch.Value*(1-script.Parent.Storage.Brake.Value)*(1-(torquesplit.Value/100))
		RL.MotorMaxTorque = 200 * (displacement.Value/2000)*clutch.Clutch.Value*(1-script.Parent.Storage.Brake.Value)*((torquesplit.Value/100))
		RR.MotorMaxTorque = 200 * (displacement.Value/2000)*clutch.Clutch.Value*(1-script.Parent.Storage.Brake.Value)*((torquesplit.Value/100))
		FL.AngularVelocity = coast/four  ------------^MULTIPLY THIS BY THE INVESE OF THE RPM [SCALE]^^^^^^^^^
		FR.AngularVelocity = coast/four  --------< MULTIPLY THIS BY GEAR (THE VALUE SHOULD BE UP THERE SOMEWHERE^^^)
		RL.AngularVelocity = coast/four
		RR.AngularVelocity = coast/four  else  end
		
		if script.Parent.Storage.EngineType.Value ~= "Electric" then
		FL.MotorMaxAcceleration = 150
		FR.MotorMaxAcceleration = 150
		RL.MotorMaxAcceleration = 150
		RR.MotorMaxAcceleration = 150
		end
 end end end 
		
		end 

elseif currentgear.Value == 1 or carSeat.Throttle == -1 or script.Parent.Functions.Engine.Value == false then
		
		
		carSeat.Parent.Transmission.Reverse.Pitch = 0
		carSeat.Parent.Differential.Idle.Pitch = 0
		carSeat.Parent.Differential.Engine.Pitch = 0
		carSeat.Parent.Engine.Intake.Pitch = 0
		--carSeat.Parent.Engine.Blowoff.Pitch = 0
		if rpm.Value > 0 then
		rpm.Value = rpm.Value - decay.Value
		else
			rpm.Value = 0
			
	end	
end
end