function Steering(E)local u=60/(1/E)if _MSteer then local E=math.max(1,(mouse.ViewSizeX*_Tune.Peripherals.MSteerWidth)/200)local u=_Tune.Peripherals.MSteerDZone/100 local z=(mouse.X-mouse.ViewSizeX/2)/E if math.abs(z)<=u then _GSteerT=0 else _GSteerT=(math.max(math.min(math.abs(z)-u,1-u),0)/(1-u))^_Tune.MSteerExp*(z/math.abs(z))end end _GSteerC=_GSteerC+(_GSteerT-_GSteerC)*(_Tune.LeanSpeed*u)bike.Body.bal.LeanGyro.cframe=CFrame.new(bike.Body.bal.CFrame.p,bike.Body.bal.CFrame.p+bike.Body.bal.CFrame.lookVector)*CFrame.Angles(0,0,(_GSteerC*_Tune.LeanProgressiveness)*(math.rad(_Tune.MaxLean)/(bike.DriveSeat.Velocity.Magnitude+_Tune.LeanProgressiveness))-_GSteerC*math.rad(_Tune.MaxLean))bike.FrontSection.TripleTreeHinge.SteeringGyro.CFrame=bike.Body.SteeringHinge.CFrame*CFrame.Angles(math.rad(_GSteerT*_Tune.SteerAngle),0,0)bike.FrontSection.TripleTreeHinge.SteeringGyro.MaxTorque=Vector3.new(_Tune.SteerMaxTorque*math.max((_Tune.LowSpeedCut-bike.DriveSeat.Velocity.Magnitude)/_Tune.LowSpeedCut,0)^2,0,0)end if UserInputService.TouchEnabled then local E=script.Parent:WaitForChild("\066\117\116\116\111\110\115")local u=E:WaitForChild("\076\101\102\116")local z=E:WaitForChild("\082\105\103\104\116")local o=E:WaitForChild("\066\114\097\107\101")local G=E:WaitForChild("\071\097\115")local r=E.Downshift local f=E.Upshift local v=E:WaitForChild("\072\097\110\100\098\114\097\107\101")local a=coroutine.wrap(function()while true do wait(.5)if _TMode=="\077\097\110\117\097\108"or _TMode=="\068\067\084"then r.Visible=true f.Visible=true else r.Visible=false f.Visible=false end end end)a()E.Visible=true local function k(E,u)if E.UserInputState==Enum.UserInputState.Begin then _GSteerT=-1 _SteerL=true else if _SteerR then _GSteerT=1 else _GSteerT=0 end _SteerL=false end end u.InputBegan:Connect(k)u.InputEnded:Connect(k)local function Y(E,u)if E.UserInputState==Enum.UserInputState.Begin then _GSteerT=1 _SteerR=true else if _SteerL then _GSteerT=-1 else _GSteerT=0 end _SteerR=false end end z.InputBegan:Connect(Y)z.InputEnded:Connect(Y)local function I(E,u)if E.UserInputState==Enum.UserInputState.Begin then _InThrot=1 _TTick=tick()else _InThrot=_Tune.IdleThrottle/100 _BTick=tick()end end G.InputBegan:Connect(I)G.InputEnded:Connect(I)local function H(E,u)if E.UserInputState==Enum.UserInputState.Begin then _InBrake=1 else _InBrake=0 end end o.InputBegan:Connect(H)o.InputEnded:Connect(H)local function i(E,u)if E.UserInputState==Enum.UserInputState.Begin then _PBrake=not _PBrake elseif E.UserInputState==Enum.UserInputState.End then if bike.DriveSeat.Velocity.Magnitude>5 then _PBrake=false end end end v.InputBegan:Connect(i)v.InputEnded:Connect(i)local function Q(E,u)if(_IsOn and((_TMode=="\065\117\116\111"and _CGear<=1)and _Tune.AutoShiftVers=="\078\101\119")or _TMode=="\068\067\084"or _TMode=="\077\097\110\117\097\108")and E.UserInputState==Enum.UserInputState.Begin then if not _ShiftDn then _ShiftDn=true end end end r.InputBegan:Connect(Q)local function g(E,u)if(_IsOn and((_TMode=="\065\117\116\111"and _CGear<1)and _Tune.AutoShiftVers=="\078\101\119")or _TMode=="\068\067\084"or _TMode=="\077\097\110\117\097\108")and E.UserInputState==Enum.UserInputState.Begin then if not _ShiftUp then _ShiftUp=true end end end f.InputBegan:Connect(g)end
--[[Steering]]

function Steering(dt)
	local deltaTime = (60 / (1 / dt))
	--Mouse Steer
	if _MSteer then
		local msWidth = math.max(1, mouse.ViewSizeX * _Tune.Peripherals.MSteerWidth / 200)
		local mdZone = _Tune.Peripherals.MSteerDZone / 100
		local mST = ((mouse.X - mouse.ViewSizeX / 2) / msWidth)
		if math.abs(mST) <= mdZone then
			_GSteerT = 0
		else
			_GSteerT = (math.max(math.min((math.abs(mST) - mdZone), (1 - mdZone)), 0) / (1 - mdZone)) ^ _Tune.MSteerExp
				* (mST / math.abs(mST))
		end
	end

	_GSteerC = (_GSteerC + ((_GSteerT - _GSteerC) * (_Tune.LeanSpeed * deltaTime)))

	--Apply Steering
	bike.Body.bal.LeanGyro.cframe = CFrame.new(
		bike.Body.bal.CFrame.p,
		bike.Body.bal.CFrame.p + bike.Body.bal.CFrame.lookVector
	) * CFrame.Angles(
		0,
		0,
		(
			(_GSteerC * _Tune.LeanProgressiveness)
				* (math.rad(_Tune.MaxLean) / (bike.DriveSeat.Velocity.Magnitude + _Tune.LeanProgressiveness))
			- (_GSteerC * math.rad(_Tune.MaxLean))
		)
	)

	--Apply Low Speed Steering
	bike.FrontSection.TripleTreeHinge.SteeringGyro.CFrame = bike.Body.SteeringHinge.CFrame
		* CFrame.Angles(math.rad(_GSteerT * _Tune.SteerAngle), 0, 0)
	bike.FrontSection.TripleTreeHinge.SteeringGyro.MaxTorque = Vector3.new(
		_Tune.SteerMaxTorque
			* ((math.max((_Tune.LowSpeedCut - bike.DriveSeat.Velocity.Magnitude) / _Tune.LowSpeedCut, 0)) ^ 2),
		0,
		0
	)
end

if UserInputService.TouchEnabled then
	local Buttons = script.Parent:WaitForChild("Buttons")
	local Left = Buttons:WaitForChild("Left")
	local Right = Buttons:WaitForChild("Right")
	local Brake = Buttons:WaitForChild("Brake")
	local Gas = Buttons:WaitForChild("Gas")
	local Downshift = Buttons.Downshift
	local Upshift = Buttons.Upshift
	local Handbrake = Buttons:WaitForChild("Handbrake")

	local Thread = coroutine.wrap(function()
		while true do
			wait(0.5)
			if _TMode == "Manual" or _TMode == "DCT" then
				Downshift.Visible = true
				Upshift.Visible = true
			else
				Downshift.Visible = false
				Upshift.Visible = false
			end
		end
	end)
	Thread()
	Buttons.Visible = true

	local function LeftTurn(Touch, GPE)
		if Touch.UserInputState == Enum.UserInputState.Begin then
			_GSteerT = -1
			_SteerL = true
		else
			if _SteerR then
				_GSteerT = 1
			else
				_GSteerT = 0
			end
			_SteerL = false
		end
	end
	Left.InputBegan:Connect(LeftTurn)
	Left.InputEnded:Connect(LeftTurn)
	--Left.InputChanged:Connect(LeftTurn)

	local function RightTurn(Touch, GPE)
		if Touch.UserInputState == Enum.UserInputState.Begin then
			_GSteerT = 1
			_SteerR = true
		else
			if _SteerL then
				_GSteerT = -1
			else
				_GSteerT = 0
			end
			_SteerR = false
		end
	end
	Right.InputBegan:Connect(RightTurn)
	Right.InputEnded:Connect(RightTurn)
	--Right.InputChanged:Connect(RightTurn)

	local function TouchThrottle(input, GPE)
		if input.UserInputState == Enum.UserInputState.Begin then
			_InThrot = 1
			_TTick = tick()
		else
			_InThrot = _Tune.IdleThrottle / 100
			_BTick = tick()
		end
	end
	Gas.InputBegan:Connect(TouchThrottle)
	Gas.InputEnded:Connect(TouchThrottle)
	--Gas.InputChanged:Connect(TouchThrottle)

	local function TouchBrake(input, GPE)
		if input.UserInputState == Enum.UserInputState.Begin then
			_InBrake = 1
		else
			_InBrake = 0
		end
	end
	Brake.InputBegan:Connect(TouchBrake)
	Brake.InputEnded:Connect(TouchBrake)
	--Brake.InputChanged:Connect(TouchBrake)

	local function TouchHandbrake(input, GPE)
		if input.UserInputState == Enum.UserInputState.Begin then
			_PBrake = not _PBrake
		elseif input.UserInputState == Enum.UserInputState.End then
			if bike.DriveSeat.Velocity.Magnitude > 5 then
				_PBrake = false
			end
		end
	end
	Handbrake.InputBegan:Connect(TouchHandbrake)
	Handbrake.InputEnded:Connect(TouchHandbrake)

	local function TouchDownshift(input, GPE)
		if
			(
				(_IsOn and ((_TMode == "Auto" and _CGear <= 1) and _Tune.AutoShiftVers == "New") or _TMode == "DCT")
				or _TMode == "Manual"
			) and input.UserInputState == Enum.UserInputState.Begin
		then
			if not _ShiftDn then
				_ShiftDn = true
			end
		end
	end

	Downshift.InputBegan:Connect(TouchDownshift)

	local function TouchUpshift(input, GPE)
		if
			(
				(_IsOn and ((_TMode == "Auto" and _CGear < 1) and _Tune.AutoShiftVers == "New") or _TMode == "DCT")
				or _TMode == "Manual"
			) and input.UserInputState == Enum.UserInputState.Begin
		then
			if not _ShiftUp then
				_ShiftUp = true
			end
		end
	end
	Upshift.InputBegan:Connect(TouchUpshift)
end
