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;
}
});
});```