#how would i stop a player from mining a block if there score isnt high enough
1 messages · Page 1 of 1 (latest)
will the after event stil run if the block is broken by someone who isnt the level needed?
Use the before event because you need the .cancel method
And you event.cancel = true if the player doesn’t have the required score
ok and this also wont run the after event right?
No the before and after events are seperate events
After event only runs when the block actually breaks
Before event runs right before the after event( before the block is broken)
So you can cancel it and the after event won’t run
as simple as js world.beforeEvents.playerBreakBlock.subscribe(ev => { const { block, player, itemStack } = ev; ev.cancel = true; });
how do i choose a block
thought so thanks
if (block === "minecraft:dirt") {…}```
ok, thanks
The block parameter is grabbed from the event like coddy showed here
yeah just saw that
whats the itemStack for?
It’s the ItemStack used to break the block
so the item used
Yea
const ob = "rank"
world.beforeEvents.playerBreakBlock.subscribe((ev)=>{
const {block,player,itemStack:item} = ev
const scoreboard = world.scoreboard.getObjective(ob) ?? system.run(()=> world.scoreboard.addObjective(ob))
const score = scoreboard.getScore(player) ?? 0
if (score < 5 && block.typeId == "minecraft:dirt" && item.typeId == "minecraft:diamond_sword") return ev.cancel = true
})
-# thank you for answering lol
Nw
simple sample.
this helped thanks
wait, I'm not kinda sure but I don't think you can use system.run() after the ?? Operator
it can
that's nice I guess
oh, wait it can't
yeah, but it work, idk why, it still create objective
it makes sense why because ?? Is a left hand right hand shit
yep, it ignores the system.run
yup, best to push it all in system.run
let obj = world.scorebord.getObjective();
if (!obj) obj = world.scoreboard.addObjective();```
this works fine
nope, it will report an error that the target cannot be obtained before checking the if condition
funny thing, I don't have that problem at all... Never thrown an error at me
I mostly used that way and yeah no probs
hmm, i'm wrong?
Sorry, but I never said your wrong what I said is I never have an error lol
yep, ik but this happen with me
lel
shouldnt this be js if (block.typeId === "minecraft:dirt") {…}
tho I'm curious can you send your script
yeah.
const ob = "rank"
world.beforeEvents.playerBreakBlock.subscribe((ev)=>{
const {block,player,itemStack:item} = ev
let obj = world.scorebord.getObjective(ob);
if (!obj) obj = world.scoreboard.addObjective(ob);
const score = obj.getScore(player) ?? 0
if (score < 5 && block.typeId == "minecraft:dirt" && item.typeId == "minecraft:diamond_sword") return ev.cancel = true
})
ok
I actually don't get why I don't have that error lol
xD
I didn't if (!obj) obj = ... it
damn, I'm getting old asf I keep forgetting shirs
that's what I meant I don't have that error... Mb mb
nah, thanks to you i also know more about it
Oh yea 😭