Help making an inventory open/close system with ContextActionService?

Hey everyone, so I’m trying to make a menu open/close when the player pushes Tab using ContextActionService, but I’m not sure how to do that. I’ve coded the script below, but it doesn’t work. What should I do?

-- Variables --
local inventory = script.Parent
local player = game.Players.LocalPlayer
local ContextActionService = game:GetService("ContextActionService")

-- Open Inventory --
local function openInventory()
	inventory.Visible = true
end

-- Close Inventory --
local function closeInventory()
	inventory.Visible = false
end

-- Controller --
Enum.KeyCode.Tab.Activated:Connect(function()
	if inventory.Active == false then
		ContextActionService:UnbindAction("closeInventory", closeInventory)
		ContextActionService:BindAction("openInventory", openInventory, false, Enum.KeyCode.Z)
	elseif inventory.Active == true then
		ContextActionService:UnbindAction("openInventory", openInventory)
		ContextActionService:BindAction("closeInventory", closeInventory, false, Enum.KeyCode.Z)
	else
		return
	end
end)

Thanks in advance!

Where is the script located because it won’t work in server side areas

It’s in a local script in StarterGUI