Button is not working when I add ContextActionService to my code. Please help!

Hello! Before I added ContextActionService to my inventory system, it worked just fine when I clicked it. Now, when I click on the inventory button, it no longer opens; but if you use ContextActionService, it works fine. Can you help?

local function OpenInventory(ActionName, InputState, InputObject)
	if InputState == Enum.UserInputState.Begin then
		game.Players.LocalPlayer.PlayerGui.Sounds.Click4:Play()
		game.Players.LocalPlayer.PlayerGui.Inventory.Frame.Visible = not game.Players.LocalPlayer.PlayerGui.Inventory.Frame.Visible
	end
end
script.Parent.MouseButton1Click:Connect(OpenInventory)

local ContextActionService = game:GetService("ContextActionService")
ContextActionService:BindAction("OpenInventory", OpenInventory, false, Enum.KeyCode.Backquote, Enum.KeyCode.X)

Thanks, WE

local function OpenInventory(ActionName, InputState, InputObject)
game.Players.LocalPlayer.PlayerGui.Sounds.Click4:Play()
game.Players.LocalPlayer.PlayerGui.Inventory.Frame.Visible = not game.Players.LocalPlayer.PlayerGui.Inventory.Frame.Visible
end
script.Parent.MouseButton1Click:Connect(OpenInventory)

local ContextActionService = game:GetService("ContextActionService")
ContextActionService:BindAction("OpenInventory", OpenInventory, false, Enum.KeyCode.Backquote, Enum.KeyCode.X)

How would I be able to make it so if I let go of `, the menu would not disappear?

Basically did this a “cheap” way, but it will work.

script.Parent.MouseButton1Click:Connect(function()
	OpenInventory("OpenInventory", Enum.UserInputState.Begin, nil)
end)

Know any other way, let me know!