#Help
1 messages · Page 1 of 1 (latest)
[Scripting][error]-ReferenceError: Native function [Entity::runCommand] does not have required privileges. at <anonymous> (boussole.js:345)
Image
help
send your code
case "vol":
if (data.sender.hasTag("Fondateur")) {
data.sender.runCommand("gamemode creative @s");
return;
}
return;
it doesn't work
//beforeEvent (read-only) scope
//originated from: world.beforeEvents[eventName].subscribe()
entity.runCommand() //Privilage error
entity.teleport() //Privilage error
//Exiting beforeEvent scope
system.run(()=>{
//working
entity.runCommand()
entity.teleport()
})
There are multiple ways to exit beforeEvent (read-only) scope. system.run() is one of them.
this code (and probably nearby code as well) needs to be within a world.afterEvents.worldLoad.subscribe(() => {}) event
my solution if your code is not within a beforeEvent, Gega's solution if it is
Thanks you ^^
If you're dealing with EarlyExecution privilege in the new 2.0.0-beta you can simply:
import { world } from "@minecraft/server";
//within EarlyExecution scope
world.sendMessage() //Privilage Error
world.getDimension() //Privilage Error
dimension.runCommand() //Privilage Error
//exiting scope
await null;
//your old code below
world.sendMessage() //working
world.getDimension() //working
dimension.runCommand() //working
worldLoad events is the intended way, but await null; is quite compact
thats pretty cool
i tried that but doesnt work
Wow, very informative on your end, how do I make a solution out of this information?
-# (Send the error at least)
I tried this method
import { world, system } from "@minecraft/server"
world.afterEvents.worldLoad.subscribe(() => {
import("./old_main")
})
ok
but adding score doesnt work
Oh wait so most of our base code now has to be wrapped in this event?
That isn't privilage error. That's ur fault.
yeahh
If you feel the "intended" way, sure
Ok so that would fix alot of stuff, does that include events inside this event?
Oh haha, well what's the correct / best method?
i mean i did this and nearly everything is fixed
system.run also technically work
Oh shoot smart
Yeah my scoreboard database broke
i think you gotta put a system.beforeEvent for it
imma try and get back to you
nope doesnt work cuz my scoreboard based commands are getting exported to other files
What's the code in there
import { world, system } from "@minecraft/server";
export function addScore(target, objective, amount) {
try {
target.runCommandAsync(`scoreboard players add @s ${objective} ${amount}`);
} catch (error) {
console.error(`Error adding score for ${target.name} in ${objective}: ${error}`);
}
}
system.runInterval(() => {
addScore(player, "afktime", 1);
console.warn("ADD SCORE WORKS")
})
they removed runCommandAsync
use native method bruhh
i forgot
would just saying runCommand work?
yeah
yeah it does