local s=script.Parent.Bike.Value local N=game:GetService("\085\115\101\114\073\110\112\117\116\083\101\114\118\105\099\101")local g=false local b=false local I=0 local D=false function DealWithInput(s)if N:GetFocusedTextBox()==nil and not g then if s.KeyCode==Enum.KeyCode[WheelieButton]and s.UserInputState==Enum.UserInputState.Begin then D=true I=1 elseif s.KeyCode==Enum.KeyCode[WheelieButton]and s.UserInputState==Enum.UserInputState.End then D=false I=0 end if s.UserInputType.Name:find("\071\097\109\101\112\097\100")then if s.KeyCode==Enum.KeyCode.Thumbstick1 then if s.Position.Y>=0 then local N=math.min(.99,DeadZone/100)if math.abs(s.Position.Y)>N then D=false I=(s.Position.Y-N)/(1-N)else D=false I=0 end else local N=math.min(.99,DeadZone/100)if math.abs(s.Position.Y)>N then D=false I=(s.Position.Y+N)/(1-N)else D=false I=0 end end end end end end N.InputBegan:connect(DealWithInput)N.InputChanged:connect(DealWithInput)N.InputEnded:connect(DealWithInput)if not s.Body.Weight:FindFirstChild("\119\104\101\101\108\105\101")then gyro=Instance.new("\066\111\100\121\071\121\114\111")gyro.Name="\119\104\101\101\108\105\101"gyro.Parent=s.Body.Weight else gyro=s.Body.Weight.wheelie end s.Body.Weight:WaitForChild("\119\104\101\101\108\105\101")s.DriveSeat.ChildRemoved:connect(function(N)gyro.D=0 gyro.MaxTorque=Vector3.new(0,0,0)gyro.P=0 gyro.cframe=CFrame.new(s.Body.Weight.CFrame.p,s.Body.Weight.CFrame.p+s.Body.Weight.CFrame.lookVector)*CFrame.Angles(0,0,0)end)WheelieDivider=math.max(1,WheelieDivider)StoppieDivider=math.max(1,StoppieDivider)while wait(clock)do g=script.Parent.ControlsOpen.Value if D then WheelieOutput=-I*(script.Parent.Values.Throttle.Value-script.Parent.Values.Brake.Value)else WheelieOutput=I end if script.Parent.Values.Throttle.Value>.1 then gyro.D=WheelieD*(-math.min(WheelieOutput,0)*script.Parent.Values.Throttle.Value)gyro.MaxTorque=Vector3.new(WheelieTq*(-math.min(WheelieOutput,0)*script.Parent.Values.Throttle.Value),0,0)gyro.P=WheelieP*(-math.min(WheelieOutput,0)*script.Parent.Values.Throttle.Value)gyro.cframe=CFrame.new(s.Body.Weight.CFrame.p,s.Body.Weight.CFrame.p+s.Body.Weight.CFrame.lookVector)*CFrame.Angles(-((math.min(WheelieOutput,0)*WheelieMultiplier)/WheelieDivider)*script.Parent.Values.Throttle.Value-s.Body.Weight.CFrame.lookVector.Y,0,0)elseif script.Parent.Values.Brake.Value>.1 then gyro.D=StoppieD*(math.min(-WheelieOutput,0)*script.Parent.Values.Brake.Value)gyro.MaxTorque=Vector3.new(StoppieTq*(math.min(-WheelieOutput,0)*script.Parent.Values.Brake.Value),0,0)gyro.P=StoppieP*(math.min(-WheelieOutput,0)*script.Parent.Values.Brake.Value)gyro.cframe=CFrame.new(s.Body.Weight.CFrame.p,s.Body.Weight.CFrame.p+s.Body.Weight.CFrame.lookVector)*CFrame.Angles(((math.min(-WheelieOutput,0)*StoppieMultiplier)/StoppieDivider)*script.Parent.Values.Brake.Value-s.Body.Weight.CFrame.lookVector.Y,0,0)else gyro.D=0 gyro.MaxTorque=Vector3.new(0,0,0)gyro.P=0 gyro.cframe=CFrame.new(s.Body.Weight.CFrame.p,s.Body.Weight.CFrame.p+s.Body.Weight.CFrame.lookVector)*CFrame.Angles(0,0,0)end end
--Dont touch
local car = script.Parent.Bike.Value
local UserInputService = game:GetService("UserInputService")
local _InControls = false
local wheelie = false
local WheelieInput = 0
local KeyWhel = false

function DealWithInput(input)
	if (UserInputService:GetFocusedTextBox() == nil) and not _InControls then
		if (input.KeyCode == Enum.KeyCode[WheelieButton]) and input.UserInputState == Enum.UserInputState.Begin then
			KeyWhel = true
			WheelieInput = 1
		elseif (input.KeyCode == Enum.KeyCode[WheelieButton]) and input.UserInputState == Enum.UserInputState.End then
			KeyWhel = false
			WheelieInput = 0
		end

		if input.UserInputType.Name:find("Gamepad") then
			--Gamepad Wheelie
			if input.KeyCode == Enum.KeyCode.Thumbstick1 then
				if input.Position.Y >= 0 then
					local cDZone = math.min(0.99, DeadZone / 100)
					if math.abs(input.Position.Y) > cDZone then
						KeyWhel = false
						WheelieInput = (input.Position.Y - cDZone) / (1 - cDZone)
					else
						KeyWhel = false
						WheelieInput = 0
					end
				else
					local cDZone = math.min(0.99, DeadZone / 100)
					if math.abs(input.Position.Y) > cDZone then
						KeyWhel = false
						WheelieInput = (input.Position.Y + cDZone) / (1 - cDZone)
					else
						KeyWhel = false
						WheelieInput = 0
					end
				end
			end
		end
	end
end

UserInputService.InputBegan:connect(DealWithInput)
UserInputService.InputChanged:connect(DealWithInput)
UserInputService.InputEnded:connect(DealWithInput)

if not car.Body.Weight:FindFirstChild("wheelie") then
	gyro = Instance.new("BodyGyro")
	gyro.Name = "wheelie"
	gyro.Parent = car.Body.Weight
else
	gyro = car.Body.Weight.wheelie
end

car.Body.Weight:WaitForChild("wheelie")

car.DriveSeat.ChildRemoved:connect(function(child)
	gyro.D = 0
	gyro.MaxTorque = Vector3.new(0, 0, 0)
	gyro.P = 0
	gyro.cframe = CFrame.new(car.Body.Weight.CFrame.p, car.Body.Weight.CFrame.p + car.Body.Weight.CFrame.lookVector)
		* CFrame.Angles(0, 0, 0)
end)

WheelieDivider = math.max(1, WheelieDivider)

StoppieDivider = math.max(1, StoppieDivider)

while wait(clock) do
	_InControls = script.Parent.ControlsOpen.Value

	if KeyWhel then
		WheelieOutput = -WheelieInput * (script.Parent.Values.Throttle.Value - script.Parent.Values.Brake.Value)
	else
		WheelieOutput = WheelieInput
	end

	if script.Parent.Values.Throttle.Value > 0.1 then
		gyro.D = WheelieD * (-(math.min(WheelieOutput, 0)) * script.Parent.Values.Throttle.Value)
		gyro.MaxTorque =
			Vector3.new(WheelieTq * (-(math.min(WheelieOutput, 0)) * script.Parent.Values.Throttle.Value), 0, 0)
		gyro.P = WheelieP * (-(math.min(WheelieOutput, 0)) * script.Parent.Values.Throttle.Value)
		gyro.cframe = CFrame.new(car.Body.Weight.CFrame.p, car.Body.Weight.CFrame.p + car.Body.Weight.CFrame.lookVector)
			* CFrame.Angles(
				(
					-(math.min(WheelieOutput, 0) * WheelieMultiplier / WheelieDivider)
					* script.Parent.Values.Throttle.Value
				) - car.Body.Weight.CFrame.lookVector.Y,
				0,
				0
			)
	elseif script.Parent.Values.Brake.Value > 0.1 then
		gyro.D = StoppieD * ((math.min(-WheelieOutput, 0)) * script.Parent.Values.Brake.Value)
		gyro.MaxTorque =
			Vector3.new(StoppieTq * ((math.min(-WheelieOutput, 0)) * script.Parent.Values.Brake.Value), 0, 0)
		gyro.P = StoppieP * ((math.min(-WheelieOutput, 0)) * script.Parent.Values.Brake.Value)
		gyro.cframe = CFrame.new(car.Body.Weight.CFrame.p, car.Body.Weight.CFrame.p + car.Body.Weight.CFrame.lookVector)
			* CFrame.Angles(
				((math.min(-WheelieOutput, 0) * StoppieMultiplier / StoppieDivider) * script.Parent.Values.Brake.Value)
					- car.Body.Weight.CFrame.lookVector.Y,
				0,
				0
			)
	else
		gyro.D = 0
		gyro.MaxTorque = Vector3.new(0, 0, 0)
		gyro.P = 0
		gyro.cframe = CFrame.new(car.Body.Weight.CFrame.p, car.Body.Weight.CFrame.p + car.Body.Weight.CFrame.lookVector)
			* CFrame.Angles(0, 0, 0)
	end
end
