Your code runs successfully with my equipment after replacing the last row
hero.moveXY(coin.pos.x, coin.pos.y)
with
hero.move(coin.pos)
I always replace moveXY with move when possible. MoveXY has a hidden loop inside it and it’s blocking or slowing some actions