This might be of help to you if you are running v2. This is a similar script in space-lua which adds the completed date/timestamp to the task when you check the task, and removes it when you uncheck it.
Currently the task:StateChange has a known issue in which the event isn’t fired for task which are not on the current page