Car.AncestryChanged:Connect(function()if not Car:IsDescendantOf(Workspace)then unbindActions()LocalVehicleSeating.ExitSeat()LocalVehicleSeating.DisconnectFromSeatExitEvent(onExitSeat)script.Disabled=true ProximityPromptService.Enabled=true end end)local function S(S,G,E)if G==Enum.UserInputState.Begin then LocalVehicleSeating.ExitSeat()end end local function G(S,G,E)local F=E.KeyCode local o=Keymap.getData(F)if not o then return end local d=o.Axis local e=0 if d then e=E.Position:Dot(d)else e=(G==Enum.UserInputState.Begin or G==Enum.UserInputState.Change)and 1 or 0 end e=e*(o.Sign or 1)_rawInput[F]=e if o.Pass then return Enum.ContextActionResult.Pass end end local function E(S)local G=Keymap[S]local E=0 local F=E for S,G in ipairs(G)do local o=_rawInput[G.KeyCode]if math.abs(o)>F then E=o F=math.abs(E)end end return E end ContextActionService:BindAction(EXIT_ACTION_NAME,S,false,Keymap.EnterVehicleGamepad,Keymap.EnterVehicleKeyboard)ContextActionService:BindActionAtPriority(RAW_INPUT_ACTION_NAME,G,false,Enum.ContextActionPriority.High.Value,unpack(Keymap.allKeys()))

Car.AncestryChanged:Connect(function()
	if not Car:IsDescendantOf(Workspace) then
		unbindActions()

		LocalVehicleSeating.ExitSeat()
		LocalVehicleSeating.DisconnectFromSeatExitEvent(onExitSeat)
		-- stop seated anim
		--print("car removed from workspace")

		script.Disabled = true
		ProximityPromptService.Enabled = true
	end
end)

local function exitVehicle(action, inputState, inputObj)
	if inputState == Enum.UserInputState.Begin then
		LocalVehicleSeating.ExitSeat()
		-- stop seated anim
	end
end

local function _updateRawInput(_, inputState, inputObj)
	local key = inputObj.KeyCode
	local data = Keymap.getData(key)

	if not data then 
		return
	end

	local axis = data.Axis
	local val = 0

	if axis then
		val = inputObj.Position:Dot(axis)
	else
		val = (inputState == Enum.UserInputState.Begin or inputState == Enum.UserInputState.Change) and 1 or 0
	end

	val = val * (data.Sign or 1)

	_rawInput[key] = val

	if data.Pass then
		return Enum.ContextActionResult.Pass
	end
end

local function _calculateInput(action)
	-- Loop through all mappings for this action and calculate a resultant value from the raw input
	local mappings = Keymap[action]
	local val = 0
	local absVal = val

	for _, data in ipairs(mappings) do
		local thisVal = _rawInput[data.KeyCode]
		if math.abs(thisVal) > absVal then
			val = thisVal
			absVal = math.abs(val)
		end
	end

	return val
end

ContextActionService:BindAction(
	EXIT_ACTION_NAME,
	exitVehicle,
	false,
	Keymap.EnterVehicleGamepad,
	Keymap.EnterVehicleKeyboard
)

ContextActionService:BindActionAtPriority(
	RAW_INPUT_ACTION_NAME,
	_updateRawInput,
	false,
	Enum.ContextActionPriority.High.Value,
	unpack(Keymap.allKeys()))
