function VehicleGui.EnableDriverControls(S)S.driverControlsEnabled=true if S.touchEnabled then S:DisplayTouchDriveControls()end end function VehicleGui.EnableSpeedo(S)S.speedoFrame.Visible=true end function VehicleGui.DisableSpeedo(S)S.speedoFrame.Visible=false end function VehicleGui.DisplayTouchDriveControls(S)S.brakeButton.Visible=true S.accelButton.Visible=true local k=false local F=false local w=false local function W()if k and F or not k and not F then S.throttleInput=0 elseif k then S.throttleInput=1 elseif F then S.throttleInput=-1 end if w then S.handBrakeInput=1 else S.handBrakeInput=0 end end S.accelButton.InputBegan:Connect(function(F)if F.UserInputType==Enum.UserInputType.Touch then k=true S.accelButton.ImageTransparency=1 S.accelButton.Pressed.ImageTransparency=0 W()end end)S.accelButton.InputEnded:Connect(function(F)if F.UserInputType==Enum.UserInputType.Touch then k=false S.accelButton.ImageTransparency=0 S.accelButton.Pressed.ImageTransparency=1 W()end end)local p=0 local z=0 S.brakeButton.InputBegan:Connect(function(k)if k.UserInputType==Enum.UserInputType.Touch then if tick()-p<=DOUBLE_TAP_THRESHOLD then w=true else z=tick()F=true end S.brakeButton.ImageTransparency=1 S.brakeButton.Pressed.ImageTransparency=0 W()end end)S.brakeButton.InputEnded:Connect(function(k)if k.UserInputType==Enum.UserInputType.Touch then if not w then if tick()-z<=SINGLE_TAP_THRESHOLD then p=tick()end end z=0 w=false F=false S.brakeButton.ImageTransparency=0 S.brakeButton.Pressed.ImageTransparency=1 W()end end)end function VehicleGui.EnableTouchControls(S)if S.touchEnabled then return end S.touchEnabled=true disableJumpButton()S:ConfigureButtons()if S.driverControlsEnabled then S:DisplayTouchDriveControls()end end function VehicleGui.DisableTouchControls(S)if not S.touchEnabled then return end S.touchEnabled=false enableJumpButton()S.brakeButton.Visible=false S.accelButton.Visible=false end function VehicleGui.EnableKeyboardUI(S)S.speedoFrame.Size=UDim2.new(0,400,0,90)S.speedoOn.Size=S.speedoFrame.Size S.speedoOff.Size=S.speedoFrame.Size S.speedoFrame.Position=UDim2.new(.5,0,1,-40)S.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"S.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"S.speedText.TextSize=40 S.speedText.Size=UDim2.new(0,60,0,40)S.speedText.Position=UDim2.new(0,215,0,94)S.unitText.TextSize=20 S.unitText.Size=UDim2.new(0,30,0,20)S.unitText.Position=UDim2.new(0,225,0,90)S:DisableTouchControls()end function VehicleGui.EnableTouchUI(S)S.speedoFrame.Size=UDim2.new(0,240,0,54)S.speedoOn.Size=S.speedoFrame.Size S.speedoOff.Size=S.speedoFrame.Size S.speedoFrame.Position=UDim2.new(.5,0,1,-20)S.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"S.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"S.speedText.TextSize=24 S.speedText.Size=UDim2.new(0,36.0,0,24)S.speedText.Position=UDim2.new(0,120,0,54)S.unitText.TextSize=12 S.unitText.Size=UDim2.new(0,18.0,0,12)S.unitText.Position=UDim2.new(0,125,0,54)S:EnableTouchControls()end function VehicleGui.EnableGamepadUI(S)S.speedoFrame.Size=UDim2.new(0,600,0,135)S.speedoOn.Size=S.speedoFrame.Size S.speedoOff.Size=S.speedoFrame.Size S.speedoFrame.Position=UDim2.new(.5,0,1,-40)S.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"S.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"S.speedText.TextSize=60 S.speedText.Size=UDim2.new(0,90,0,60)S.speedText.Position=UDim2.new(0,315,0,140)S.unitText.TextSize=30 S.unitText.Size=UDim2.new(0,45,0,30)S.unitText.Position=UDim2.new(0,325,0,135)S:DisableTouchControls()end return VehicleGui
--If both DriverControls are enabled and touch controls are enabled then the accelerate and brake buttons will appear.
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
