ContextActionService script only detects UserInoutType.End

  1. What do you want to achieve? Keep it simple and clear!
    **I would like to enable a certain GUI whenever Tab key is pressed and disable it when the Tab key is released **

  2. What is the issue? Include screenshots / videos if possible!
    It only detects when I let go of Tab and not when I start to press Tab

Just tell me what went wrong, why it’s wrong and how to fix it. :>

Here’s the script:

local CAS = game:GetService("ContextActionService")
local TI = "ToggleInventory"
local function toggleInventory(actionName, InputState, InputObject)
	local inventory = plr.PlayerGui:WaitForChild("main_inventory")
	if InputState == Enum.UserInputState.Begin then
		inventory.Enabled = true
		print("enabled")
	elseif InputState == Enum.UserInputState.End then
		inventory.Enabled = false
		print("disabled")
	end
	
end

CAS:BindAction(TI, toggleInventory, true, Enum.KeyCode.Tab)