#Could anyone pls help me with this script pls?

1 messages · Page 1 of 1 (latest)

boreal crown
#

Anyone pls help?

#
function getScore(target, objective) {
    try {
        target.runCommand(`scoreboard players add @s ${objective} 0`);
        return world.scoreboard.getObjective(objective).getScore(target);
    } catch {
        return 0;
    }
}

system.runInterval(() => {
    world.scoreboard.removeObjective(`Koth`)
    world.scoreboard.clearObjectiveAtDisplaySlot(DisplaySlotId.Sidebar)
    world.scoreboard.addObjective(`Koth`).displayName(`§6KOTH`)
    world.scoreboard.setObjectiveAtDisplaySlot(DisplaySlotId.Sidebar, {objective: `Koth`})
world.sendMessage(`§6The Koth event has started!`);
}, 24000);
system.runInterval(() => {
for (const player of world.getPlayers()) {
    if (getScore(player, "Koth") > 99) {
        world.scoreboard.getObjective(`balance`).addScore(player, 5000)
        world.sendMessage(`§e${player.name} §6has won the Koth event!`);
        world.scoreboard.removeObjective(`Koth`)
        world.scoreboard.clearObjectiveAtDisplaySlot(DisplaySlotId.Sidebar)
    }
}
}, 20);```
median mountain
boreal crown
#

line 13 "world.scoreboard.removeObjective("Koth")

#

it says errors and it doesnt seem to be working every 20 mins

median mountain
#

what the error say

boreal crown
#

but i can only remember the line number

#

it was like issue with removing the scoreboard

#

when idk why?

median mountain
#

alr
let me see

boreal crown
#

ok

#

thats the error

median mountain
#


function getScore(target, objective) {
    try {
        target.runCommand(`scoreboard players add @s ${objective} 0`);
        return world.scoreboard.getObjective(objective).getScore(target);
    } catch {
        return 0;
    }
}

system.runInterval(() => {
    if(world.scoreboard.getObjective(`balance`)) world.scoreboard.removeObjective(`Koth`)
    world.scoreboard.clearObjectiveAtDisplaySlot(DisplaySlotId.Sidebar)
    world.scoreboard.addObjective(`Koth`).displayName(`§6KOTH`)
    world.scoreboard.setObjectiveAtDisplaySlot(DisplaySlotId.Sidebar, {objective: `Koth`})
world.sendMessage(`§6The Koth event has started!`);
}, 24000);
system.runInterval(() => {
for (const player of world.getPlayers()) {
    if (getScore(player, "Koth") > 99) {
        world.scoreboard.getObjective(`balance`).addScore(player, 5000)
        world.sendMessage(`§e${player.name} §6has won the Koth event!`);
        if(world.scoreboard.getObjective(`balance`)) world.scoreboard.removeObjective(`Koth`)
        world.scoreboard.clearObjectiveAtDisplaySlot(DisplaySlotId.Sidebar)
    }
}
}, 20);```
#

@boreal crown

boreal crown
#

yh?

median mountain
#

you need to check if the objective is there before trying to remove it
if(world.scoreboard.getObjective(balance))
i added it to [the code above](#1306023735471636502 message)

boreal crown
#

@median mountain

#

line 10 = system.runInterval

median mountain
#

import {world,system} from "@minecraft/server";

#

add in top of your code

boreal crown
#

ok

#

says this again?

#

@median mountain

median mountain
#

send the full code

boreal crown
#

ok

#
import {world,system} from "@minecraft/server";

function getScore(target, objective) {
    try {
        target.runCommand(`scoreboard players add @s ${objective} 0`);
        return world.scoreboard.getObjective(objective).getScore(target);
    } catch {
        return 0;
    }
}

system.runInterval(() => {
    if(world.scoreboard.getObjective(`balance`)) world.scoreboard.removeObjective(`Koth`)
    world.scoreboard.clearObjectiveAtDisplaySlot(DisplaySlotId.Sidebar)
    world.scoreboard.addObjective(`Koth`).displayName(`§6KOTH`)
    world.scoreboard.setObjectiveAtDisplaySlot(DisplaySlotId.Sidebar, {objective: `Koth`})
world.sendMessage(`§6The Koth event has started!`);
}, 3000);
system.runInterval(() => {
for (const player of world.getPlayers()) {
    if (getScore(player, "Koth") > 99) {
        world.scoreboard.getObjective(`balance`).addScore(player, 5000)
        world.sendMessage(`§e${player.name} §6has won the Koth event!`);
        if(world.scoreboard.getObjective(`balance`)) world.scoreboard.removeObjective(`Koth`)
        world.scoreboard.clearObjectiveAtDisplaySlot(DisplaySlotId.Sidebar)
    }
}
}, 20);```
median mountain
# boreal crown ```js import {world,system} from "@minecraft/server"; function getScore(target,...
import {world,system} from "@minecraft/server";

function getScore(target, objective) {
    try {
        target.runCommand(`scoreboard players add @s ${objective} 0`);
        return world.scoreboard.getObjective(objective).getScore(target);
    } catch {
        return 0;
    }
}

system.runInterval(() => {
    if(world.scoreboard.getObjective(`Koth`)) world.scoreboard.removeObjective(`Koth`)
    world.scoreboard.clearObjectiveAtDisplaySlot(DisplaySlotId.Sidebar)
    world.scoreboard.addObjective(`Koth`).displayName(`§6KOTH`)
    world.scoreboard.setObjectiveAtDisplaySlot(DisplaySlotId.Sidebar, {objective: `Koth`})
world.sendMessage(`§6The Koth event has started!`);
}, 3000);
system.runInterval(() => {
for (const player of world.getPlayers()) {
    if (getScore(player, "Koth") > 99) {
        world.scoreboard.getObjective(`balance`).addScore(player, 5000)
        world.sendMessage(`§e${player.name} §6has won the Koth event!`);
        if(world.scoreboard.getObjective(`Koth`)) world.scoreboard.removeObjective(`Koth`)
        world.scoreboard.clearObjectiveAtDisplaySlot(DisplaySlotId.Sidebar)
    }
}
}, 20);
boreal crown
#

@median mountain

median mountain
# boreal crown <@704346785811923016>
import {world,system} from "@minecraft/server";

function getScore(target, objective) {
    try {
        target.runCommand(`scoreboard players add @s ${objective} 0`);
        return world.scoreboard.getObjective(objective).getScore(target);
    } catch {
        return 0;
    }
}

system.runInterval(() => {
    if(world.scoreboard.getObjective(`Koth`)) world.scoreboard.removeObjective(`Koth`)
    world.scoreboard.clearObjectiveAtDisplaySlot("Sidebar")
    world.scoreboard.addObjective(`Koth`).displayName(`§6KOTH`)
    world.scoreboard.setObjectiveAtDisplaySlot("Sidebar", {objective: `Koth`})
world.sendMessage(`§6The Koth event has started!`);
}, 3000);
system.runInterval(() => {
for (const player of world.getPlayers()) {
    if (getScore(player, "Koth") > 99) {
        world.scoreboard.getObjective(`balance`).addScore(player, 5000)
        world.sendMessage(`§e${player.name} §6has won the Koth event!`);
        if(world.scoreboard.getObjective(`Koth`)) world.scoreboard.removeObjective(`Koth`)
        world.scoreboard.clearObjectiveAtDisplaySlot("Sidebar")
    }
}
}, 20);
boreal crown
median mountain
# boreal crown
import {world,system} from "@minecraft/server";

function getScore(target, objective) {
    try {
        target.runCommand(`scoreboard players add @s ${objective} 0`);
        return world.scoreboard.getObjective(objective).getScore(target);
    } catch {
        return 0;
    }
}

system.runInterval(() => {
    if(world.scoreboard.getObjective(`Koth`)) world.scoreboard.removeObjective(`Koth`)
    world.scoreboard.clearObjectiveAtDisplaySlot("Sidebar")
    world.scoreboard.addObjective(`Koth`,`§6KOTH`)
    world.scoreboard.setObjectiveAtDisplaySlot("Sidebar", {objective: `Koth`})
world.sendMessage(`§6The Koth event has started!`);
}, 3000);
system.runInterval(() => {
for (const player of world.getPlayers()) {
    if (getScore(player, "Koth") > 99) {
        world.scoreboard.getObjective(`balance`).addScore(player, 5000)
        world.sendMessage(`§e${player.name} §6has won the Koth event!`);
        if(world.scoreboard.getObjective(`Koth`)) world.scoreboard.removeObjective(`Koth`)
        world.scoreboard.clearObjectiveAtDisplaySlot("Sidebar")
    }
}
}, 20);
boreal crown
#

@median mountain

median mountain
# boreal crown <@704346785811923016>
import {world,system} from "@minecraft/server";

const koth_scoreboard = world.scoreboard.getObjective(`Koth`) || world.scoreboard.addObjective(`Koth`,`§6KOTH`);
const BALANCE_SCOREBOARD = world.scoreboard.getObjective(`balance`);

system.runInterval(() => {
    if (koth_scoreboard) {
        world.scoreboard.removeObjective(`Koth`)
        world.scoreboard.clearObjectiveAtDisplaySlot("Sidebar")
    }
    world.scoreboard.setObjectiveAtDisplaySlot("Sidebar", {objective: koth_scoreboard})
    world.sendMessage(`§6The Koth event has started!`);
}, 3000);

system.runInterval(() => {
    for (const player of world.getPlayers()) {
        if (getScore(player, `Koth`) > 99) {
            BALANCE_SCOREBOARD.addScore(player, 5000);
            world.sendMessage(`§e${player.name} §6has won the Koth event!`);
            world.scoreboard.removeObjective(`Koth`);
            world.scoreboard.clearObjectiveAtDisplaySlot("Sidebar")
        }
    }
}, 20);
boreal crown
#

@median mountain

median mountain
# boreal crown
import {world,system} from "@minecraft/server";

const koth_scoreboard = world.scoreboard.getObjective(`Koth`) || world.scoreboard.addObjective(`Koth`,`§6KOTH`);
const BALANCE_SCOREBOARD = world.scoreboard.getObjective(`balance`)??world.scoreboard.addObjective(`balance`,`§6BALANCE`);

system.runInterval(() => {
    if (koth_scoreboard) {
        world.scoreboard.removeObjective(`Koth`)
        world.scoreboard.clearObjectiveAtDisplaySlot("Sidebar")
    }
    world.scoreboard.setObjectiveAtDisplaySlot("Sidebar", {objective: koth_scoreboard})
    world.sendMessage(`§6The Koth event has started!`);
}, 3000);

system.runInterval(() => {
    for (const player of world.getPlayers()) {
        if (koth_scoreboard.getScore(player, `Koth`) > 99) {
            BALANCE_SCOREBOARD.addScore(player, 5000);
            world.sendMessage(`§e${player.name} §6has won the Koth event!`);
            world.scoreboard.removeObjective(`Koth`);
            world.scoreboard.clearObjectiveAtDisplaySlot("Sidebar")
        }
    }
}, 20);

boreal crown
median mountain
# boreal crown
import {world,system} from "@minecraft/server";

const koth_scoreboard = world.scoreboard.getObjective(`Koth`) || world.scoreboard.addObjective(`Koth`,`§6KOTH`);
const BALANCE_SCOREBOARD = world.scoreboard.getObjective(`balance`)??world.scoreboard.addObjective(`balance`,`§6BALANCE`);

system.runInterval(() => {
    if (koth_scoreboard) {
        world.scoreboard.removeObjective(`Koth`)
        world.scoreboard.clearObjectiveAtDisplaySlot("Sidebar")
    }
    world.scoreboard.setObjectiveAtDisplaySlot("Sidebar", {objective: koth_scoreboard})
    world.sendMessage(`§6The Koth event has started!`);
}, 3000);

system.runInterval(() => {
    for (const player of world.getPlayers()) {
        if (koth_scoreboard.getScore(player) > 99) {
            BALANCE_SCOREBOARD.addScore(player, 5000);
            world.sendMessage(`§e${player.name} §6has won the Koth event!`);
            world.scoreboard.removeObjective(`Koth`);
            world.scoreboard.clearObjectiveAtDisplaySlot("Sidebar")
        }
    }
}, 20);

rapid tulip
#

🤔 You're ensuring the objective doesn't exist and then immediately attempting to display it?

boreal crown
#

what would i do then to fix thi?

#

this*?

#

@median mountain

median mountain
boreal crown
#

ok

median mountain
#
import {world,system} from "@minecraft/server";

const koth_scoreboard = world.scoreboard.getObjective(`Koth`) || world.scoreboard.addObjective(`Koth`,`§6KOTH`);
const BALANCE_SCOREBOARD = world.scoreboard.getObjective(`balance`)??world.scoreboard.addObjective(`balance`,`§6BALANCE`);

system.runInterval(() => {
    if (koth_scoreboard) {
        world.scoreboard.removeObjective(`Koth`)
        world.scoreboard.clearObjectiveAtDisplaySlot("Sidebar")
    }
    world.scoreboard.addObjective(`Koth`,`§6KOTH`)
    world.scoreboard.setObjectiveAtDisplaySlot("Sidebar", {objective: koth_scoreboard})
    world.sendMessage(`§6The Koth event has started!`);
}, 3000);

system.runInterval(() => {
    for (const player of world.getPlayers()) {
        if (koth_scoreboard.getScore(player) > 99) {
            BALANCE_SCOREBOARD.addScore(player, 5000);
            world.sendMessage(`§e${player.name} §6has won the Koth event!`);
            world.scoreboard.removeObjective(`Koth`);
            world.scoreboard.addObjective(`Koth`,`§6KOTH`)
            world.scoreboard.clearObjectiveAtDisplaySlot("Sidebar")
        }
    }
}, 20);

rapid tulip
#

So the goal is to clear all participants from the scoreboard? That's what I assume you intend by deleting the objective and reintroducing it.

boreal crown
#

Yes

rapid tulip
#

Isn't there a native method for just that?

boreal crown
#

A koth system?

#

wym

rapid tulip
#

For clearing all the participants in a scoreboard objective.

median mountain
#

removeParticipant?

boreal crown
#

it shows the sidebar

#

but why does it not show the players?

#

with the score 0

rapid tulip
# median mountain removeParticipant?

Hm, I suppose that would do.

const KOTHObj = world.scoreboard.getObjective('Koth');
for(const participant of KOTHObj.getParticipants()) {
  KOTHObj.removeParticipant(participant);
}
#

No need to delete the objective and reintroduce it, or to clear the sidebar and set it again

boreal crown
#

why are they not shown on the scoreboard?

#

with a default score of 0

#

@median mountain

median mountain
#

what dose the getScore function do?
"scoreboard players add @s ${objective} 0"?

rapid tulip
boreal crown
#
import {world,system} from "@minecraft/server";

const koth_scoreboard = world.scoreboard.getObjective(`Koth`) || world.scoreboard.addObjective(`Koth`,`§6KOTH`);
const BALANCE_SCOREBOARD = world.scoreboard.getObjective(`balance`)??world.scoreboard.addObjective(`balance`,`§6BALANCE`);

system.runInterval(() => {
    if (koth_scoreboard) {
        world.scoreboard.removeObjective(`Koth`)
        world.scoreboard.clearObjectiveAtDisplaySlot("Sidebar")
    }
    world.scoreboard.addObjective(`Koth`,`§6KOTH`)
    world.scoreboard.setObjectiveAtDisplaySlot("Sidebar", {objective: koth_scoreboard})
    world.scoreboard.player.addScore.koth_scoreboard(player, 0)
    world.sendMessage(`§6The Koth event has started!`);
}, 300);

system.runInterval(() => {
    for (const player of world.getPlayers()) {
        if (koth_scoreboard.getScore(player) > 99) {
            BALANCE_SCOREBOARD.addScore(player, 5000);
            world.sendMessage(`§e${player.name} §6has won the Koth event!`);
            world.scoreboard.removeObjective(`Koth`);
            world.scoreboard.addObjective(`Koth`,`§6KOTH`)
            world.scoreboard.clearObjectiveAtDisplaySlot("Sidebar")
        }
    }
}, 20);```
#

why is it wrong?

rapid tulip
#

Let's revisit your original sample. The intention for the function, as I understand it, is to do the following:

  • Every 20 minutes, reset the KOTH scoreboard and announce the KOTH event.
  • Every second, if one player has a KOTH score of 100 or more, announce them as the winner, award that player 5000 balance, then clear the KOTH score from the sidebar.
#

I'm not sure why the scripting engine is throwing an error for something that is supposed to be synchronous. Let's assume that removeObjective and addObjective are fallible in this regard.

median mountain
#

this is the best i can think of not knowing your compete plan

import { world, system } from "@minecraft/server";

const scoreboard = world.scoreboard;
const KOTHObj = scoreboard.getObjective("Koth") ?? scoreboard.addObjective("Koth", "§6KOTH");
const balanceObj = scoreboard.getObjective("balance") ?? scoreboard.addObjective("balance", "§6Balance");

system.runInterval(() => {
  for (const participant of KOTHObj.getParticipants()) {
    KOTHObj.removeParticipant(participant);
    KOTHObj.setScore(participant,0)
  }
  scoreboard.setObjectiveAtDisplaySlot("Sidebar", { objective: KOTHObj });
  world.sendMessage(`§6The Koth event has started!`);
}, 3000);

system.runInterval(() => {
  for (const player of world.getPlayers()) {
    const KothScore = KOTHObj.getScore(player);
    if(KothScore === undefined) KOTHObj.setScore(player,0)
    if(KOTHObj.getScore(player) > 99){
        balanceObj.addScore(player, 5000);
        world.sendMessage(`§e${player.name} §6has won the Koth event!`);
        scoreboard.clearObjectiveAtDisplaySlot("Sidebar");
    }
  }
}, 20);
boreal crown
#

thankyou @median mountain

median mountain
#

your wlc
thanks to sprunkles too

boreal crown
#

umm i have a problem

#

@median mountain

#

i only want it to say it once

#

idk why it says it like so many times

rapid tulip
#

In the 20-tick interval, you probably want to reset all the KOTH participants' scores again once one player wins.

boreal crown
#

how would i do that?

rapid tulip
#

See the bit in the 3000-tick interval's function that starts with for(const participant of KOTHObj.getParticipants()) {? That's precisely what this loop is doing.

#

Could just copy and paste that loop

boreal crown
#

ok ill lyk if errors

#

still says it

#

so many times

median mountain
#
import { world, system } from "@minecraft/server";

let isKothEvent = false;
const scoreboard = world.scoreboard;
const KOTHObj = scoreboard.getObjective("Koth") ?? scoreboard.addObjective("Koth", "§6KOTH");
const balanceObj = scoreboard.getObjective("balance") ?? scoreboard.addObjective("balance", "§6Balance");

system.runInterval(() => {
  if(isKothEvent) return
  scoreboard.setObjectiveAtDisplaySlot("Sidebar", { objective: KOTHObj });
  world.sendMessage(`§6The Koth event has started!`);
  isKothEvent = true
}, 3000);

system.runInterval(() => {
  for (const player of world.getPlayers()) {
    const KothScore = KOTHObj.getScore(player);
    if(KothScore === undefined) KOTHObj.setScore(player,0)
    if(KOTHObj.getScore(player) > 99){
        balanceObj.addScore(player, 5000);
        world.sendMessage(`§e${player.name} §6has won the Koth event!`);
        scoreboard.clearObjectiveAtDisplaySlot("Sidebar");
        isKothEvent = false
        for (const participant of KOTHObj.getParticipants()) {
            KOTHObj.removeParticipant(participant);
            KOTHObj.setScore(participant,0)
        }
    }
  }
}, 20);
#

the reset is only needed when player win

#

also added isKothEvent so the next event don't trigger without someone wining

boreal crown
#

line 24 error

median mountain
#

i edited the code

boreal crown
#

tysm

#

it works

median mountain
#

cool

boreal crown
#

could u pls help me fix this @median mountain

#

players offline?

median mountain
rapid tulip
#

This is a normal function of Bedrock; real players tied to a scoreboard will display as "Player Offline" once they leave.

boreal crown
#

i want it to only show the guys in the game

median mountain
#

i have no idea if that possible, sorry
i can think of a work around, save his score when he leave and remove hem from the obj, and add hem back when he join

upbeat vortex
#

then you have to save the score value when they leave somehow

rapid tulip
#

Have two objectives: One that holds scores internally, then one that displays scores on the sidebar. Periodically delete all display scores, then copy all online players to it.

#

In commands this would look like the following:

# restore_display.mcfunction
scoreboard players reset * display
execute as @a run scoreboard players operation @s display = @s internal