#ActionForm Body shows incorrect score

1 messages · Page 1 of 1 (latest)

compact moth
#
export async function menu_shop(player) {
    const menu = new ActionFormData()    
//...
    menu.title('§m§f§f§lMenu§r§g - Shop')
    menu.body('You have §6§g§l'+`${world.scoreboard.getObjective('coins').getScore(player)}`+'§r§6§p Coins\n§tWarning: There is no Warning')
    let r = await ForceOpen(player, menu)
    if (r.selection == 0) {
        if (world.scoreboard.getObjective('coins').getScore(player) >= 5) {
            player.runCommandAsync(`scoreboard players remove @s coins 5`)
            player.runCommandAsync(`give @s jungle_boat`)
            player.sendMessage(`Bought §lBoat§r for §g5 Coins`)
        }
        else {
            player.sendMessage(`You need at least §g5 Coins`)
        }
    }
    if (r.selection >= -1) {
        system.run(() => {
            menu_shop(player);
        });
    }
}```

Can someone tell me why the menu body doesnt display the right amount of coins? its always delayed, and after purchasing an item and reopening the menu the amount of coins shown stays the same, unless i open it twice. In short: the coins score updates to slow
gloomy reef
#

here's one if you'd like to use itjs export function getScore(target, objective) { try { return (world.scoreboard.getObjective(objective))?.getScore(target) ?? 0; } catch (error) { return 0; } }

compact moth
#

what exactly does this solve?

#

my issue is not that it fires errors or the ui wont open, the issue is that a outdated number is beeing shown

gloomy reef
#

the getScore should always provide you with an updated score

#

also it might even be the way you're calling the function that it doesn't display the updated score

compact moth
#

okay i will try it out

#

its sadly still the same issue

gloomy reef
#

¯_(ツ)_/¯