Make UIS only listen when script.parent (tool) is currently equipped

uis.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		punch()
	elseif input.UserInputType == Enum.UserInputType.MouseButton2 then
		critical()
	end
end)

How do I make the uis only listens when the script.parent is current equipped? I’ve tried if script.parent.Equipped but if it’s equipped once then it continue to work even if it’s unequipped.

Store the tool’s equipped state and update it whenever the tool is equipped or unequipped.

Example code:

local equipped = false
tool.Equipped:Connect(function()
    equipped = true
end)

tool.Unequipped:Connect(function()
    equipped = false
end)    

UserInputService.InputBegan:Connect(function(input)
    if not equipped then
        return
    end

    if input.UserInputType == Enum.UserInputType.MouseButton1 then
        punch()
    elseif input.UserInputType == Enum.UserInputType.MouseButton2 then
        critical()
    end
end)

the equipped state isn’t updating.
could it be because it’s a local script?