#Script change

1 messages · Page 1 of 1 (latest)

molten aurora
#
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

gentle citrus
#
const { scoreboardIdentity } = player
```On `getScore`
molten aurora
#

awesome thanks could i get you to look at another script i had made for me

gentle citrus
#

Sure

molten aurora
#

its supposed to display a sidebar and convert larger numbers to be like 1k instead of 1000 and so on but its not showing up

#

i know very little about scripts

#

im trying to learn but it takes time

gentle citrus
#

Tick event is removed for a long time

#

Use system.runInterval

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

system.runInterval(() => {
  // Your code from `tick` event
})
molten aurora
#

ok ill try that thanks

#

its not generating the sidebar on the screen

        {
            "module_name": "@minecraft/server",
            "version": "1.3.0-beta"
        },
        {
            "module_name": "@minecraft/server-gametest",
            "version": "1.1.0-beta"
        },
        {
            "module_name": "@minecraft/server-ui",
            "version": "1.1.0-beta"
        }
    ],```
are these the right dependencies i need?
#

or could there be something else wrong with the code?

gentle citrus
#

Did you import the system there?

molten aurora
#

yes i have the system at the top

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

and i replaced the

world.events.tick.subscribe(function (evd) {```
with 
```js
system.runInterval(() => {```
molten aurora
#

ok there is something seriously wrong with the script
my content log is getting spammed with
[2023-06-10 20:25:53:610 ERROR] [Scripting] TypeError: Unexpected type passed to function argument [2]. at <anonymous> (main_atm.js:28) even though there is not a single atm in the world spawned

#
world.afterEvents.entityHit.subscribe(data => {
  let source = data.entity;
  let { entity, hitEntity } = data
  if (hitEntity.typeId == "pokeworld:atm" && entity.typeId == "minecraft:player") {```
something within this section is making it go haywire