local function h(h)local C=h.CFrame.upVector local I=math.deg(math.acos(C:Dot(Vector3.new(0,1,0))))return I>=MIN_FLIP_ANGLE end local function C(C,I)local F=C.Parent.Parent local b=script:WaitForChild("\066\117\116\116\111\110\071\117\105\080\114\111\116\111\116\121\112\101")local O=b:Clone()O.Name="\066\117\116\116\111\110\071\117\105"O.Enabled=true O.Adornee=C.Parent local y=O:WaitForChild("\066\117\116\116\111\110\073\109\097\103\101")local S=O:WaitForChild("\070\108\105\112\073\109\097\103\101")local n=O:WaitForChild("\066\097\099\107\103\114\111\117\110\100\068\101\115\107\116\111\112")local Q=O:WaitForChild("\066\097\099\107\103\114\111\117\110\100\067\111\110\115\111\108\101")local f=O:WaitForChild("\066\117\116\116\111\110\080\114\111\109\112\116")local T local s local E local q if I==Enum.ProximityPromptInputType.Keyboard then T="\114\098\120\097\115\115\101\116\105\100\058\047\047\050\056\052\056\050\053\048\057\048\050"s="\114\098\120\097\115\115\101\116\105\100\058\047\047\050\056\052\056\050\053\048\057\048\050"E="\114\098\120\097\115\115\101\116\105\100\058\047\047\050\056\052\056\050\053\049\053\054\052"q="\114\098\120\097\115\115\101\116\105\100\058\047\047\050\056\052\056\050\053\049\053\054\052"y.Size=UDim2.new(0,36,0,36)S.Image="\114\098\120\097\115\115\101\116\105\100\058\047\047\050\056\052\056\051\048\055\057\056\051";(S:WaitForChild("\080\114\101\115\115\101\100")).Image="\114\098\120\097\115\115\101\116\105\100\058\047\047\050\056\052\056\051\048\055\057\056\051"S.Size=UDim2.new(0,44,0,44)Q.Visible=false n.Visible=true n.Size=UDim2.new(0,97,0,46)n.Position=UDim2.new(.5,28,.5,0)f.Visible=true f.Image="\114\098\120\097\115\115\101\116\105\100\058\047\047\050\057\051\053\057\049\050\053\051\054"f.Size=UDim2.new(0,36,0,36)f.Position=UDim2.new(.5,-46,.5,0)f.TextLabel.Visible=true f.TextLabel.Text=Keymap.EnterVehicleKeyboard.Name elseif I==Enum.ProximityPromptInputType.Gamepad then T="\114\098\120\097\115\115\101\116\105\100\058\047\047\050\056\052\056\054\051\053\048\050\057"s="\114\098\120\097\115\115\101\116\105\100\058\047\047\050\056\052\056\054\051\053\048\050\057"E="\114\098\120\097\115\115\101\116\105\100\058\047\047\050\056\052\056\054\051\054\053\052\053"q="\114\098\120\097\115\115\101\116\105\100\058\047\047\050\056\052\056\054\051\054\053\052\053"y.Size=UDim2.new(0,60,0,60)S.Image="\114\098\120\097\115\115\101\116\105\100\058\047\047\050\056\052\056\051\048\055\057\056\051";(S:WaitForChild("\080\114\101\115\115\101\100")).Image="\114\098\120\097\115\115\101\116\105\100\058\047\047\050\056\052\056\051\048\055\057\056\051"S.Size=UDim2.new(0,44,0,44)n.Visible=false Q.Visible=true Q.Size=UDim2.new(0,136,0,66)Q.Position=UDim2.new(.5,40,.5,0)f.Visible=true f.Size=UDim2.new(0,46,0,46)f.Position=UDim2.new(.5,-63,.5,0)f.ImageRectSize=Vector2.new(71,71)f.ImageRectOffset=Vector2.new(512,600)f.TextLabel.Visible=false local h=InputImageLibrary:GetImageLabel(Keymap.EnterVehicleGamepad,"\076\105\103\104\116")f.Image=h.Image f.ImageRectOffset=h.ImageRectOffset f.ImageRectSize=h.ImageRectSize elseif I==Enum.ProximityPromptInputType.Touch then n.Visible=false Q.Visible=false f.Visible=false T="\114\098\120\097\115\115\101\116\105\100\058\047\047\050\056\052\055\056\057\056\050\048\048"s="\114\098\120\097\115\115\101\116\105\100\058\047\047\050\056\052\055\056\057\056\051\053\052"E="\114\098\120\097\115\115\101\116\105\100\058\047\047\050\056\052\056\050\049\055\056\051\049"q="\114\098\120\097\115\115\101\116\105\100\058\047\047\050\056\052\056\050\049\056\049\048\055"y.Size=UDim2.new(0,44,0,44)S.Image="\114\098\120\097\115\115\101\116\105\100\058\047\047\050\056\052\056\049\056\055\053\053\057";(S:WaitForChild("\080\114\101\115\115\101\100")).Image="\114\098\120\097\115\115\101\116\105\100\058\047\047\050\056\052\056\049\056\055\057\056\050"S.Size=UDim2.new(0,44,0,44)y.InputBegan:Connect(function(h)C:InputHoldBegin()end)y.InputEnded:Connect(function(h)C:InputHoldEnd()end)S.InputBegan:Connect(function(h)C:InputHoldBegin()end)S.InputEnded:Connect(function(h)C:InputHoldEnd()end)O.Active=true end if h(F)then S.Visible=true y.Visible=false else S.Visible=false y.Visible=true end if F.Name=="\086\101\104\105\099\108\101\083\101\097\116"then y.Image=T y.Pressed.Image=s else y.Image=E y.Pressed.Image=q end return O end ProximityPromptService.PromptShown:Connect(function(h,I)if h.Name=="\069\110\100\111\114\115\101\100\086\101\104\105\099\108\101\080\114\111\120\105\109\105\116\121\080\114\111\109\112\116\086\049"then local F=C(h,I)F.Parent=screenGui h.PromptHidden:Wait()F.Parent=nil end end)

local function isFlipped(Seat)
	local UpVector = Seat.CFrame.upVector
	local Angle = math.deg(math.acos(UpVector:Dot(Vector3.new(0, 1, 0))))
	return Angle >= MIN_FLIP_ANGLE
end

local function createPrompt(prompt, inputType)
	local seat = prompt.Parent.Parent
	local buttonGui = script:WaitForChild("ButtonGuiPrototype")
	local promptUI = buttonGui:Clone()
	promptUI.Name = "ButtonGui"
	promptUI.Enabled = true
	promptUI.Adornee = prompt.Parent
	
	
	local EnterImageButton = promptUI:WaitForChild("ButtonImage")
	local FlipImageButton = promptUI:WaitForChild("FlipImage")
	local BackgroundDesktop = promptUI:WaitForChild("BackgroundDesktop")
	local BackgroundConsole = promptUI:WaitForChild("BackgroundConsole")
	local ButtonPrompt = promptUI:WaitForChild("ButtonPrompt")

	--Switch button type
	local DriverButtonId
	local DriverButtonPressedId
	local PassengerButtonId
	local PassengerButtonPressedId
	if inputType == Enum.ProximityPromptInputType.Keyboard then
		DriverButtonId = "rbxassetid://2848250902"
		DriverButtonPressedId = "rbxassetid://2848250902"
		PassengerButtonId = "rbxassetid://2848251564"
		PassengerButtonPressedId = "rbxassetid://2848251564"
		EnterImageButton.Size = UDim2.new(0, 36, 0, 36)
		FlipImageButton.Image = "rbxassetid://2848307983"
		FlipImageButton:WaitForChild("Pressed").Image = "rbxassetid://2848307983"
		FlipImageButton.Size = UDim2.new(0, 44, 0, 44)

		BackgroundConsole.Visible = false
		BackgroundDesktop.Visible = true
		BackgroundDesktop.Size =  UDim2.new(0, 97, 0, 46)
		BackgroundDesktop.Position = UDim2.new(0.5, 28, 0.5, 0)

		ButtonPrompt.Visible = true
		ButtonPrompt.Image = "rbxassetid://2935912536"
		ButtonPrompt.Size = UDim2.new(0, 36, 0, 36)
		ButtonPrompt.Position = UDim2.new(0.5, -46, 0.5, 0)
		ButtonPrompt.TextLabel.Visible = true

		--Display the correct key
		ButtonPrompt.TextLabel.Text = Keymap.EnterVehicleKeyboard.Name

	elseif inputType == Enum.ProximityPromptInputType.Gamepad then
		DriverButtonId = "rbxassetid://2848635029"
		DriverButtonPressedId = "rbxassetid://2848635029"
		PassengerButtonId = "rbxassetid://2848636545"
		PassengerButtonPressedId = "rbxassetid://2848636545"
		EnterImageButton.Size = UDim2.new(0, 60, 0, 60)
		FlipImageButton.Image = "rbxassetid://2848307983"
		FlipImageButton:WaitForChild("Pressed").Image = "rbxassetid://2848307983"
		FlipImageButton.Size = UDim2.new(0, 44, 0, 44)

		BackgroundDesktop.Visible = false
		BackgroundConsole.Visible = true
		BackgroundConsole.Size =  UDim2.new(0, 136, 0, 66)
		BackgroundConsole.Position = UDim2.new(0.5, 40, 0.5, 0)

		ButtonPrompt.Visible = true
		--ButtonPrompt.Image = "rbxassetid://408462759"
		ButtonPrompt.Size = UDim2.new(0, 46, 0, 46)
		ButtonPrompt.Position = UDim2.new(0.5, -63, 0.5, 0)
		ButtonPrompt.ImageRectSize = Vector2.new(71, 71)
		ButtonPrompt.ImageRectOffset = Vector2.new(512, 600)
		ButtonPrompt.TextLabel.Visible = false

		--Set the correct image for the gamepad button prompt
		local template = InputImageLibrary:GetImageLabel(Keymap.EnterVehicleGamepad, "Light")
		ButtonPrompt.Image = template.Image
		ButtonPrompt.ImageRectOffset = template.ImageRectOffset
		ButtonPrompt.ImageRectSize = template.ImageRectSize
	elseif inputType == Enum.ProximityPromptInputType.Touch then
		BackgroundDesktop.Visible = false
		BackgroundConsole.Visible = false
		ButtonPrompt.Visible = false

		DriverButtonId = "rbxassetid://2847898200"
		DriverButtonPressedId = "rbxassetid://2847898354"
		PassengerButtonId = "rbxassetid://2848217831"
		PassengerButtonPressedId = "rbxassetid://2848218107"
		EnterImageButton.Size = UDim2.new(0, 44, 0, 44)
		FlipImageButton.Image = "rbxassetid://2848187559"
		FlipImageButton:WaitForChild("Pressed").Image = "rbxassetid://2848187982"
		FlipImageButton.Size = UDim2.new(0, 44, 0, 44)
		
		EnterImageButton.InputBegan:Connect(function(input)
			prompt:InputHoldBegin()
		end)
		EnterImageButton.InputEnded:Connect(function(input)
			prompt:InputHoldEnd()
		end)
		FlipImageButton.InputBegan:Connect(function(input)
			prompt:InputHoldBegin()
		end)
		FlipImageButton.InputEnded:Connect(function(input)
			prompt:InputHoldEnd()
		end)

		promptUI.Active = true
	end
	
	if isFlipped(seat) then
		FlipImageButton.Visible = true
		EnterImageButton.Visible = false
	else
		FlipImageButton.Visible = false
		EnterImageButton.Visible = true
	end
	if seat.Name == "VehicleSeat" then
		EnterImageButton.Image = DriverButtonId
		EnterImageButton.Pressed.Image = DriverButtonPressedId
	else
		EnterImageButton.Image = PassengerButtonId
		EnterImageButton.Pressed.Image = PassengerButtonPressedId
	end

	return promptUI
end

ProximityPromptService.PromptShown:Connect(function(prompt, inputType)
	if prompt.Name == "EndorsedVehicleProximityPromptV1" then
		local promptUI = createPrompt(prompt, inputType)
		promptUI.Parent = screenGui
		prompt.PromptHidden:Wait()
		promptUI.Parent = nil
	end
end)
