local function q()if LocalPlayer.Character then return LocalPlayer.Character:FindFirstChildOfClass("\072\117\109\097\110\111\105\100")end end local U=50 local j=false local function Z()local Z=q()if j and Z then Z.JumpPower=U j=false end end local function K()local Z=q()if Z then U=Z.JumpPower Z.JumpPower=0 j=true end end function VehicleGui.Enable(q)q.gui.Enabled=true q:EnableKeyboardUI()q:ConfigureButtons()local function U(U)if U==Enum.UserInputType.Touch then q:EnableTouchUI()q:ConfigureButtons()elseif U.Value>=Enum.UserInputType.Gamepad1.Value and U.Value<=Enum.UserInputType.Gamepad8.Value then q:EnableGamepadUI()q:ConfigureButtons()elseif U==Enum.UserInputType.Keyboard then q:EnableKeyboardUI()q:ConfigureButtons()end end q.connections[#q.connections+1]=UserInputService.LastInputTypeChanged:Connect(U)U(UserInputService:GetLastInputType())function q.OnExit(U)q:Destroy()end q.localSeatModule.OnSeatExitEvent(q.OnExit)q.connections[#q.connections+1]=q.gui.AncestryChanged:Connect(function()if not q.gui:IsDescendantOf(game)then q:Destroy()end end)q.connections[#q.connections+1]=q.chassis.AncestryChanged:Connect(function()if not q.chassis:IsDescendantOf(Workspace)then q:Destroy()end end)q.connections[#q.connections+1]=q.exitButton.Activated:Connect(function()Z()q:Destroy()q.localSeatModule.ExitSeat()end)q.connections[#q.connections+1]=q.exitButton.InputBegan:Connect(function(U)if U.UserInputType==Enum.UserInputType.Touch then q.exitButton.ImageTransparency=1 q.exitButton.Pressed.ImageTransparency=0 end end)q.connections[#q.connections+1]=q.exitButton.InputEnded:Connect(function(U)if U.UserInputType==Enum.UserInputType.Touch then q.exitButton.ImageTransparency=0 q.exitButton.Pressed.ImageTransparency=1 end end)q.connections[#q.connections+1]=RunService.RenderStepped:Connect(function()local U=q.seat.Velocity local j=.6263 local Z=U.Magnitude*j local K=math.min(Z/MAX_SPEED,1)local m=math.floor(q.speedoFrame.AbsoluteSize.X*K+.5)q.speedoFrameOn.Size=UDim2.new(0,m,1,0)q.speedText.Text=tostring(math.floor(Z+.5))if q.touchEnabled then q.steeringInput=-(PlayerControlModule:GetMoveVector()).X end end)end function VehicleGui.Destroy(q)q.localSeatModule.DisconnectFromSeatExitEvent(q.OnExit)for q,U in ipairs(q.connections)do U:Disconnect()end if q.gui then q.gui:Destroy()end Z()end function VehicleGui.ConfigureButtons(q)q.accelButton.Image="\114\098\120\097\115\115\101\116\105\100\058\047\047\050\056\052\055\056\052\055\056\053\050"q.accelButton.Pressed.Image="\114\098\120\097\115\115\101\116\105\100\058\047\047\050\056\052\055\056\052\055\057\054\049"q.accelButton.Size=UDim2.new(0,70,0,70)q.accelButton.AnchorPoint=Vector2.new(1,1)q.accelButton.Position=UDim2.new(1,-24,1,-20)q.brakeButton.Size=UDim2.new(0,44,0,44)q.brakeButton.AnchorPoint=Vector2.new(1,1)q.brakeButton.Position=UDim2.new(1,-((24+q.accelButton.Size.X.Offset)+20),1,-20)q.brakeButton.Image="\114\098\120\097\115\115\101\116\105\100\058\047\047\050\056\052\055\056\052\056\051\048\052"q.brakeButton.Pressed.Image="\114\098\120\097\115\115\101\116\105\100\058\047\047\050\056\052\055\056\052\056\052\048\048"q.exitButton.Image="\114\098\120\097\115\115\101\116\105\100\058\047\047\050\056\052\055\056\053\055\057\052\056"q.exitButton.Pressed.Image="\114\098\120\097\115\115\101\116\105\100\058\047\047\050\056\052\055\056\053\056\048\051\056"q.exitButton.KeyImage.ImageRectSize=Vector2.new(0,0)q.exitButton.KeyImage.ImageRectOffset=Vector2.new(0,0)q.exitButton.KeyImage.ButtonText.Visible=false local U=UserInputService:GetLastInputType()if U==Enum.UserInputType.Touch then q.exitButton.Size=UDim2.new(0,44,0,44)q.exitButton.AnchorPoint=Vector2.new(1,1)q.exitButton.Position=UDim2.new(1,-24,1,-((20+q.accelButton.Size.Y.Offset)+20))q.exitButton.KeyImage.Image=""else q.exitButton.Size=UDim2.new(0,72,0,72)q.exitButton.AnchorPoint=Vector2.new(1,1)q.exitButton.Position=UDim2.new(1,-24,1,-((20+q.accelButton.Size.Y.Offset)+20))if U.Value>=Enum.UserInputType.Gamepad1.Value and U.Value<=Enum.UserInputType.Gamepad8.Value then local U=InputImageLibrary:GetImageLabel(Keymap.EnterVehicleGamepad,"\076\105\103\104\116")q.exitButton.KeyImage.Image=U.Image q.exitButton.KeyImage.ImageRectOffset=U.ImageRectOffset q.exitButton.KeyImage.ImageRectSize=U.ImageRectSize else q.exitButton.KeyImage.Image="\114\098\120\097\115\115\101\116\105\100\058\047\047\050\057\051\053\057\049\050\053\051\054"q.exitButton.KeyImage.ButtonText.Visible=true q.exitButton.KeyImage.ButtonText.Text=Keymap.EnterVehicleKeyboard.Name end end end
----Handle the enabling and disabling of the default roblox jump button----
local function getLocalHumanoid()
	if LocalPlayer.Character then
		return LocalPlayer.Character:FindFirstChildOfClass("Humanoid")
	end
end

local oldHumanoidJumpPower = 50
local jumpDisabled = false
local function enableJumpButton()
	local humanoid = getLocalHumanoid()
	if jumpDisabled and humanoid then
		humanoid.JumpPower = oldHumanoidJumpPower
		jumpDisabled = false
	end
end

local function disableJumpButton()
	local humanoid = getLocalHumanoid()
	if humanoid then
		oldHumanoidJumpPower = humanoid.JumpPower
		humanoid.JumpPower = 0
		jumpDisabled = true
	end
end

function VehicleGui:Enable()
	self.gui.Enabled = true

	self:EnableKeyboardUI()
	self:ConfigureButtons()
	local function UpdateInputType(inputType)
		if inputType == Enum.UserInputType.Touch then
			self:EnableTouchUI()
			self:ConfigureButtons()
		elseif
			inputType.Value >= Enum.UserInputType.Gamepad1.Value
			and inputType.Value <= Enum.UserInputType.Gamepad8.Value
		then
			self:EnableGamepadUI()
			self:ConfigureButtons()
		elseif inputType == Enum.UserInputType.Keyboard then
			self:EnableKeyboardUI()
			self:ConfigureButtons()
		end
	end
	self.connections[#self.connections + 1] = UserInputService.LastInputTypeChanged:Connect(UpdateInputType)
	UpdateInputType(UserInputService:GetLastInputType())

	--Destroy when player gets out of vehicle
	function self.OnExit(Seat)
		self:Destroy()
	end
	self.localSeatModule.OnSeatExitEvent(self.OnExit)

	--Destroy if the gui has been destroyed
	self.connections[#self.connections + 1] = self.gui.AncestryChanged:Connect(function()
		if not self.gui:IsDescendantOf(game) then
			self:Destroy()
		end
	end)

	--Destroy if vehicle is no longer in workspace
	self.connections[#self.connections + 1] = self.chassis.AncestryChanged:Connect(function()
		if not self.chassis:IsDescendantOf(Workspace) then
			self:Destroy()
		end
	end)

	--Connect the exit seat button
	self.connections[#self.connections + 1] = self.exitButton.Activated:Connect(function()
		enableJumpButton()
		self:Destroy()
		self.localSeatModule.ExitSeat()
	end)
	self.connections[#self.connections + 1] = self.exitButton.InputBegan:Connect(function(input)
		if input.UserInputType == Enum.UserInputType.Touch then
			self.exitButton.ImageTransparency = 1
			self.exitButton.Pressed.ImageTransparency = 0
		end
	end)
	self.connections[#self.connections + 1] = self.exitButton.InputEnded:Connect(function(input)
		if input.UserInputType == Enum.UserInputType.Touch then
			self.exitButton.ImageTransparency = 0
			self.exitButton.Pressed.ImageTransparency = 1
		end
	end)

	self.connections[#self.connections + 1] = RunService.RenderStepped:Connect(function()
		--Update the speedo
		local vel = self.seat.Velocity
		local mphConversion = 0.6263 -- using a 28cm = 1stud conversion rate
		local speed = vel.Magnitude * mphConversion

		local speedFraction = math.min(speed / MAX_SPEED, 1)
		local onSize = math.floor(self.speedoFrame.AbsoluteSize.X * speedFraction + 0.5)
		self.speedoFrameOn.Size = UDim2.new(0, onSize, 1, 0)
		self.speedText.Text = tostring(math.floor(speed + 0.5))

		--Update the steering input if touch controls are enabled
		if self.touchEnabled then
			self.steeringInput = -PlayerControlModule:GetMoveVector().X
		end
	end)
end

function VehicleGui:Destroy()
	self.localSeatModule.DisconnectFromSeatExitEvent(self.OnExit)
	for _, connection in ipairs(self.connections) do
		connection:Disconnect()
	end
	if self.gui then
		self.gui:Destroy()
	end
	enableJumpButton()
end

function VehicleGui:ConfigureButtons()
	--Position Accelerate Button
	self.accelButton.Image = "rbxassetid://2847847852"
	self.accelButton.Pressed.Image = "rbxassetid://2847847961"
	self.accelButton.Size = UDim2.new(0, 70, 0, 70)
	self.accelButton.AnchorPoint = Vector2.new(1, 1)
	self.accelButton.Position = UDim2.new(1, -24, 1, -20)

	--Position Brake Button
	self.brakeButton.Size = UDim2.new(0, 44, 0, 44)
	self.brakeButton.AnchorPoint = Vector2.new(1, 1)
	self.brakeButton.Position = UDim2.new(1, -(24 + self.accelButton.Size.X.Offset + 20), 1, -20)
	self.brakeButton.Image = "rbxassetid://2847848304"
	self.brakeButton.Pressed.Image = "rbxassetid://2847848400"

	--Position Exit Button
	self.exitButton.Image = "rbxassetid://2847857948"
	self.exitButton.Pressed.Image = "rbxassetid://2847858038"
	self.exitButton.KeyImage.ImageRectSize = Vector2.new(0, 0)
	self.exitButton.KeyImage.ImageRectOffset = Vector2.new(0, 0)
	self.exitButton.KeyImage.ButtonText.Visible = false

	local inputType = UserInputService:GetLastInputType()
	if inputType == Enum.UserInputType.Touch then
		self.exitButton.Size = UDim2.new(0, 44, 0, 44)
		self.exitButton.AnchorPoint = Vector2.new(1, 1)
		self.exitButton.Position = UDim2.new(1, -24, 1, -(20 + self.accelButton.Size.Y.Offset + 20))
		self.exitButton.KeyImage.Image = ""
	else
		self.exitButton.Size = UDim2.new(0, 72, 0, 72)
		self.exitButton.AnchorPoint = Vector2.new(1, 1)
		self.exitButton.Position = UDim2.new(1, -24, 1, -(20 + self.accelButton.Size.Y.Offset + 20))

		if
			inputType.Value >= Enum.UserInputType.Gamepad1.Value
			and inputType.Value <= Enum.UserInputType.Gamepad8.Value
		then
			--Set the correct image for the gamepad button prompt
			local template = InputImageLibrary:GetImageLabel(Keymap.EnterVehicleGamepad, "Light")
			self.exitButton.KeyImage.Image = template.Image
			self.exitButton.KeyImage.ImageRectOffset = template.ImageRectOffset
			self.exitButton.KeyImage.ImageRectSize = template.ImageRectSize
		else
			self.exitButton.KeyImage.Image = "rbxassetid://2935912536"
			self.exitButton.KeyImage.ButtonText.Visible = true
			self.exitButton.KeyImage.ButtonText.Text = Keymap.EnterVehicleKeyboard.Name
		end
	end
end
