#breaking blocks give money

1 messages · Page 1 of 1 (latest)

severe loom
#
world.beforeEvents.playerBreakBlock.subscribe((event) => {
  for (const block of blocks) {
    if (event.block.typeId == block.name) {
      event.cancel = true
      system.run(()=> {
        event.block.setType("air")
        add_score(event.player, block.price)
      })
    }
  }
})```
#

my bad, it's event.block.setType

#
function add_score(player, score) {
  world.scoreboard.getObjective("scoreboard name").addScore(player, score)
}```
#

no problem

#

oh, i realized you need to use system.run for this function to work

#

show the addScore function

#

glad to help

#

it be like that, your other option is to use an after event and kill the item as soon as it spawns, but there is a possibility for the item to be picked up by a hopper minecart

#

it's your choice

#

you can't cancel afterEvents

#

remove the system.run maybe

#

oh, i know why

#

you should use the broken block permutation because block is now air

severe loom
#

i think because it transformers into lit_redstone_ore block when you start mining