function VehicleGui.EnableDriverControls(L)L.driverControlsEnabled=true if L.touchEnabled then L:DisplayTouchDriveControls()end end function VehicleGui.EnableSpeedo(L)L.speedoFrame.Visible=true end function VehicleGui.DisableSpeedo(L)L.speedoFrame.Visible=false end function VehicleGui.DisplayTouchDriveControls(L)L.brakeButton.Visible=true L.accelButton.Visible=true local w=false local s=false local F=false local function m()if w and s or not w and not s then L.throttleInput=0 elseif w then L.throttleInput=1 elseif s then L.throttleInput=-1 end if F then L.handBrakeInput=1 else L.handBrakeInput=0 end end L.accelButton.InputBegan:Connect(function(s)if s.UserInputType==Enum.UserInputType.Touch then w=true L.accelButton.ImageTransparency=1 L.accelButton.Pressed.ImageTransparency=0 m()end end)L.accelButton.InputEnded:Connect(function(s)if s.UserInputType==Enum.UserInputType.Touch then w=false L.accelButton.ImageTransparency=0 L.accelButton.Pressed.ImageTransparency=1 m()end end)local H=0 local g=0 L.brakeButton.InputBegan:Connect(function(w)if w.UserInputType==Enum.UserInputType.Touch then if tick()-H<=DOUBLE_TAP_THRESHOLD then F=true else g=tick()s=true end L.brakeButton.ImageTransparency=1 L.brakeButton.Pressed.ImageTransparency=0 m()end end)L.brakeButton.InputEnded:Connect(function(w)if w.UserInputType==Enum.UserInputType.Touch then if not F then if tick()-g<=SINGLE_TAP_THRESHOLD then H=tick()end end g=0 F=false s=false L.brakeButton.ImageTransparency=0 L.brakeButton.Pressed.ImageTransparency=1 m()end end)end function VehicleGui.EnableTouchControls(L)if L.touchEnabled then return end L.touchEnabled=true disableJumpButton()L:ConfigureButtons()if L.driverControlsEnabled then L:DisplayTouchDriveControls()end end function VehicleGui.DisableTouchControls(L)if not L.touchEnabled then return end L.touchEnabled=false enableJumpButton()L.brakeButton.Visible=false L.accelButton.Visible=false end function VehicleGui.EnableKeyboardUI(L)L.speedoFrame.Size=UDim2.new(0,400,0,90)L.speedoOn.Size=L.speedoFrame.Size L.speedoOff.Size=L.speedoFrame.Size L.speedoFrame.Position=UDim2.new(.5,0,1,-40)L.speedoOn.Image="\114\098\120\097\115\115\101\116\105\100\058\047\047\050\056\052\056\051\049\050\052\049\052"L.speedoOff.Image="\114\098\120\097\115\115\101\116\105\100\058\047\047\050\056\052\056\051\049\050\056\055\056"L.speedText.TextSize=40 L.speedText.Size=UDim2.new(0,60,0,40)L.speedText.Position=UDim2.new(0,215,0,94)L.unitText.TextSize=20 L.unitText.Size=UDim2.new(0,30,0,20)L.unitText.Position=UDim2.new(0,225,0,90)L:DisableTouchControls()end function VehicleGui.EnableTouchUI(L)L.speedoFrame.Size=UDim2.new(0,240,0,54)L.speedoOn.Size=L.speedoFrame.Size L.speedoOff.Size=L.speedoFrame.Size L.speedoFrame.Position=UDim2.new(.5,0,1,-20)L.speedoOn.Image="\114\098\120\097\115\115\101\116\105\100\058\047\047\050\056\052\055\056\052\051\055\049\056"L.speedoOff.Image="\114\098\120\097\115\115\101\116\105\100\058\047\047\050\056\052\055\056\052\051\056\051\057"L.speedText.TextSize=24 L.speedText.Size=UDim2.new(0,36.0,0,24)L.speedText.Position=UDim2.new(0,120,0,54)L.unitText.TextSize=12 L.unitText.Size=UDim2.new(0,18.0,0,12)L.unitText.Position=UDim2.new(0,125,0,54)L:EnableTouchControls()end function VehicleGui.EnableGamepadUI(L)L.speedoFrame.Size=UDim2.new(0,600,0,135)L.speedoOn.Size=L.speedoFrame.Size L.speedoOff.Size=L.speedoFrame.Size L.speedoFrame.Position=UDim2.new(.5,0,1,-40)L.speedoOn.Image="\114\098\120\097\115\115\101\116\105\100\058\047\047\050\056\051\054\050\048\056\056\048\051"L.speedoOff.Image="\114\098\120\097\115\115\101\116\105\100\058\047\047\050\056\051\054\050\048\056\052\056\056"L.speedText.TextSize=60 L.speedText.Size=UDim2.new(0,90,0,60)L.speedText.Position=UDim2.new(0,315,0,140)L.unitText.TextSize=30 L.unitText.Size=UDim2.new(0,45,0,30)L.unitText.Position=UDim2.new(0,325,0,135)L:DisableTouchControls()end return VehicleGui

function VehicleGui:EnableDriverControls()
	self.driverControlsEnabled = true

	if self.touchEnabled then
		self:DisplayTouchDriveControls()
	end
end

function VehicleGui:EnableSpeedo()
	self.speedoFrame.Visible = true
end

function VehicleGui:DisableSpeedo()
	self.speedoFrame.Visible = false
end

function VehicleGui:DisplayTouchDriveControls()
	self.brakeButton.Visible = true
	self.accelButton.Visible = true

	--Read button inputs
	local ADown = false
	local BDown = false
	local HDown = false
	local function ProcessTouchThrottle()
		if (ADown and BDown) or (not ADown and not BDown) then
			self.throttleInput = 0
		elseif ADown then
			self.throttleInput = 1
		elseif BDown then
			self.throttleInput = -1
		end
		if HDown then
			self.handBrakeInput = 1
		else
			self.handBrakeInput = 0
		end
	end
	--Accel
	self.accelButton.InputBegan:Connect(function(input)
		if input.UserInputType == Enum.UserInputType.Touch then
			ADown = true
			self.accelButton.ImageTransparency = 1
			self.accelButton.Pressed.ImageTransparency = 0
			ProcessTouchThrottle()
		end
	end)
	self.accelButton.InputEnded:Connect(function(input)
		if input.UserInputType == Enum.UserInputType.Touch then
			ADown = false
			self.accelButton.ImageTransparency = 0
			self.accelButton.Pressed.ImageTransparency = 1
			ProcessTouchThrottle()
		end
	end)
	--Brake
	local lastBrakeTapTime = 0
	local brakeLastInputBegan = 0
	self.brakeButton.InputBegan:Connect(function(input)
		if input.UserInputType == Enum.UserInputType.Touch then
			if tick() - lastBrakeTapTime <= DOUBLE_TAP_THRESHOLD then
				HDown = true
			else
				brakeLastInputBegan = tick()
				BDown = true
			end
			self.brakeButton.ImageTransparency = 1
			self.brakeButton.Pressed.ImageTransparency = 0
			ProcessTouchThrottle()
		end
	end)
	self.brakeButton.InputEnded:Connect(function(input)
		if input.UserInputType == Enum.UserInputType.Touch then
			if not HDown then
				if tick() - brakeLastInputBegan <= SINGLE_TAP_THRESHOLD then
					lastBrakeTapTime = tick()
				end
			end
			brakeLastInputBegan = 0
			HDown = false
			BDown = false
			self.brakeButton.ImageTransparency = 0
			self.brakeButton.Pressed.ImageTransparency = 1
			ProcessTouchThrottle()
		end
	end)
end

function VehicleGui:EnableTouchControls()
	if self.touchEnabled then return end
	self.touchEnabled = true

	disableJumpButton()

	self:ConfigureButtons()

	if self.driverControlsEnabled then
		self:DisplayTouchDriveControls()
	end
end

function VehicleGui:DisableTouchControls()
	if not self.touchEnabled  then return end
	self.touchEnabled = false

	enableJumpButton()

	self.brakeButton.Visible = false
	self.accelButton.Visible = false
end

function VehicleGui:EnableKeyboardUI()
	self.speedoFrame.Size = UDim2.new(0, 400, 0, 90)
	self.speedoOn.Size = self.speedoFrame.Size
	self.speedoOff.Size = self.speedoFrame.Size
	self.speedoFrame.Position = UDim2.new(0.5, 0, 1, -40)
	self.speedoOn.Image = "rbxassetid://2848312414"
	self.speedoOff.Image = "rbxassetid://2848312878"
	self.speedText.TextSize = 40
	self.speedText.Size = UDim2.new(0, 60, 0, 40)
	self.speedText.Position = UDim2.new(0, 215, 0, 94)
	self.unitText.TextSize = 20
	self.unitText.Size = UDim2.new(0, 30, 0, 20)
	self.unitText.Position = UDim2.new(0, 225, 0, 90)

	self:DisableTouchControls()
end

function VehicleGui:EnableTouchUI()
	self.speedoFrame.Size = UDim2.new(0, 240, 0, 54)
	self.speedoOn.Size = self.speedoFrame.Size
	self.speedoOff.Size = self.speedoFrame.Size
	self.speedoFrame.Position = UDim2.new(0.5, 0, 1, -20)
	self.speedoOn.Image = "rbxassetid://2847843718"
	self.speedoOff.Image = "rbxassetid://2847843839"
	self.speedText.TextSize = 24
	self.speedText.Size = UDim2.new(0, 24*3*0.5, 0, 24)
	self.speedText.Position = UDim2.new(0, 120, 0, 54)
	self.unitText.TextSize = 12
	self.unitText.Size = UDim2.new(0, 12*3*0.5, 0, 12)
	self.unitText.Position = UDim2.new(0, 125, 0, 54)

	self:EnableTouchControls()
end

function VehicleGui:EnableGamepadUI()
	self.speedoFrame.Size = UDim2.new(0, 600, 0, 135)
	self.speedoOn.Size = self.speedoFrame.Size
	self.speedoOff.Size = self.speedoFrame.Size
	self.speedoFrame.Position = UDim2.new(0.5, 0, 1, -40)
	self.speedoOn.Image = "rbxassetid://2836208803"
	self.speedoOff.Image = "rbxassetid://2836208488"
	self.speedText.TextSize = 60
	self.speedText.Size = UDim2.new(0, 90, 0, 60)
	self.speedText.Position = UDim2.new(0, 315, 0, 140)
	self.unitText.TextSize = 30
	self.unitText.Size = UDim2.new(0, 45, 0, 30)
	self.unitText.Position = UDim2.new(0, 325, 0, 135)

	self:DisableTouchControls()
end

return VehicleGui
