That is not a good fix unfortunately you will run into bugs as you expand the inventory. I've seen the events and what is happening you are setting it back to 0 and then to an appropriate value every tick, flip flopping between 0 and the correct value, it's better to just set it once for simplicity and to avoid bugs. Also you can get performance issues from doing this.