How can I keep track of events of added pixels?

I’m trying to make a counter of pixels activated whenever I want, with a button pressed or a key, then stop and reset count.
I’m having this error: attempt to index a nil value field getter