Tweak the code so it can be used to enter normal seats

So im trying to make a system like jailbreak so whenever you get near any seat (driver or passenger) it appears an e button that you press to enter and exit.

I took a code from okeansky that works only for vehicle seat and i would like to know if someone have idea to make it work in normal seats too.

video link:

code:

local replicatedStorage = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")
local runService = game:GetService("RunService")
local userInputService = game:GetService("UserInputService")

local carEnterGui = replicatedStorage.CarEnterGui

local character = players.LocalPlayer.Character

local closestVehicle, gui, currentSeat

character.Humanoid.Died:Connect(function()
	if gui then
		gui:Destroy()
	end
	
	script.Disabled = true
end)

userInputService.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.F then
		if gui then
			gui.Parent:Sit(character.Humanoid)
		elseif currentSeat then
			currentSeat:Sit(nil)
			wait()
			character.HumanoidRootPart.CFrame = character.HumanoidRootPart.CFrame + Vector3.new(0, 0, 5)
		end
	end
end)

character.Humanoid.Seated:Connect(function(active, currentSeatPart)
	if active then
		currentSeat = currentSeatPart
	else
		currentSeat = nil
	end
end)

local toggleGui = function(toggle)
	if gui then
		gui:Destroy()
		gui = nil
	end
	
	if toggle == true then
		gui = carEnterGui:Clone()
		gui.Parent = closestVehicle:FindFirstChildWhichIsA("VehicleSeat")
	end
end

runService.RenderStepped:Connect(function()
	local maxDistance = 10
	local newClosestVehicle
	
	for _, vehicle in pairs(workspace.Vehicles:GetChildren()) do
		if (vehicle.DriveSeat.Position - character.HumanoidRootPart.Position).magnitude <= maxDistance and not vehicle.DriveSeat.Occupant then
			maxDistance = (vehicle.DriveSeat.Position - character.HumanoidRootPart.Position).magnitude
			newClosestVehicle = vehicle
		end
	end

	closestVehicle = newClosestVehicle

	if closestVehicle and not currentSeat then
		toggleGui(true)
	else
		toggleGui(false)
	end	
end)

hierarchy:

image
image

You could just use a ProximityPrompt and use the ProximityPrompt.Triggered event then do what ever from there

I tried using this but it doesnt work for me, its a nightmare, it only works to enter the vehicle, it wont work leaving it, but if you could explain how i could do it

i got the same issue i am making a plane game and i also need an exit button 2 years later lol

lol, its sometimes painful, im trying to use OOP for everything now, but if i would try to do sommething like this, nothing adds up in my mind, i woudnt know where to put the code, like, should there be a code to leave inside the airplane code or character code? Its sometimes pretty hard to handle these kind of interactions, especially the ones involving input