Slight change needed. When the Inventory is open, it needs to wait until you close it.
Use player.opened_self, and player.opened for this.
If it is closed, update immediately. Otherwise, wait via an Ontick for it to close. This will avoid the scroll reset when getting a new item.