#Trying to check players score to run if block (RESOLVED)

1 messages · Page 1 of 1 (latest)

quasi lantern
#

I have a script that when a certain block is broke a particle appears on the block. It has been working but I now want to only have the particle appear of the player has a certain score. I am a complete noob at javascript, been trying to get my head around it reading the official documentation. Here is my code:

const blockTypes = [
  "minecraft:stone",
  "minecraft:dirt",
  //...
];

const scoreboard = world.scoreboard
const score = scoreboard.getObjective("score_test")

world.afterEvents.playerBreakBlock.subscribe((event) => {
  const { brokenBlockPermutation } = event;
  const player = world.getAllPlayers();
  const scores = score.getScore(player);

  blockTypes.forEach((id) => {
    if (brokenBlockPermutation.matches(id) && scores < 10) {
      event.player.dimension.runCommand(
        `particle minecraft:basic_flame_particle ${event.block.x} ${
          event.block.y + 1
        } ${event.block.z}`
      );
      return;
    }
  });
});

I am getting the error "TypeError: Native variant type conversion failed. at <anonymous> (Test.js:15)

This was my old code, which works, but without the score part in the "if"

const blockTypes = [
  "minecraft:stone",
  "minecraft:dirt",
  //...
];

world.afterEvents.playerBreakBlock.subscribe((event) => {
  const { brokenBlockPermutation } = event;
  blockTypes.forEach((id) => {
    if (brokenBlockPermutation.matches(id)) {
      event.player.dimension.runCommand(
        `particle minecraft:basic_flame_particle ${event.block.x} ${
          event.block.y + 1
        } ${event.block.z}`
      );
      return;
    }
  });
});```
pallid saffron
#
const player = world.getAllPlayers()``` return an array of online players. `getScore()` only accept `String`, `Entity Class`, or `scoreboardIdentity` not an array.

Do this instead:```js
const player = event.player```(Just directly access the provided player class from the event.)
quasi lantern