import {
world, Player
} from '@minecraft/server';
import {
ActionFormData,
MessageFormData,
ModalFormData
} from '@minecraft/server-ui';
export function getScore(player, objective) {
const { scoreboard: scoreboardIdentity } = player
if (!(player instanceof Player)) return;
try {
return world.scoreboard.getObjective(objective).getScore(scoreboardIdentity)
} catch (e) {
return 0;
}
}
world.afterEvents.entityHit.subscribe(data => {
let source = data.entity;
let { entity, hitEntity } = data
if (hitEntity.typeId == "pokeworld:atm" && entity.typeId == "minecraft:player") {
let MForm2 = new ModalFormData()
let playerNameList = []
for (let players of world.getPlayers()) {
let playerName = players.name
playerNameList.push(`§c${playerName}`)
}
MForm2.title(`§l§9You have §l§a$${getScore(source, "Money")}`)
MForm2.dropdown("§9Send to", playerNameList)
MForm2.slider("§9Amount To Send §a$", 1000, getScore(source, "Money"), 100, 1000)
MForm2.show(source).then((response) => {
try {
source.runCommandAsync(`tellraw @s {\"rawtext\":[{\"text\":\" \"}]}`);
} catch (e) {
console.warn(e)
}
if (getScore(source, "Money") >= response.formValues[1]) {
try {
const send_to = playerNameList[response.formValues[0]].replace("§c", "")
source.runCommandAsync(`scoreboard players remove @s Money ${response.formValues[1]}`)
source.runCommandAsync(`scoreboard players add "${send_to}" Money ${response.formValues[1]}`)
source.runCommandAsync(`tellraw @s {\"rawtext\":[{\"text\":\"§aYou sent ${send_to} $${response.formValues[1]}, You have $${getScore(source, "Money")} Left.\"}]}`)
source.runCommandAsync(`tellraw "${send_to}" {\"rawtext\":[{\"text\":\"§aYou were sent $${response.formValues[1]} from ${source.nameTag}\"}]}`)
} catch { }
} else {
try {
source.runCommandAsync(`tellraw @s {\"rawtext\":[{\"text\":\"§cYou need $1000 to Money transfer you Have $${getScore(source, "Money")}\"}]}`)
} catch { }
}
})
}
})
the script is not reading the players scoreboard anymore for the slider can someone show me what changed please