#HELP IN SCRIPTING

1 messages · Page 1 of 1 (latest)

rough chasm
#

with only one item in ur inventory?...

#

change plr.runCommandAsync to plr.sendMessage just to check how that code works

safe gust
#

alr

#

it works

#

so the problem probably comes from the async command

rough chasm
#

have u tried with a lot of items in ur inventory?

safe gust
#

wdym?

rough chasm
#

random items in ur inv

safe gust
#

like have i tried with other items then my custom key

#

yeah

#

i tried with doiamonds and it works

rough chasm
#

i mean this kind of "random items in inv"

safe gust
#

yeah

#

i tried

#

nvm i figured out the problem

rough chasm
#
const inv = plr.getComponent("inventory").container
let crate_key = 0
for (let i = 0; i < inv.size; i++) {
    const item = inv.getItem(i)
    if (!item || item.typeId !== 'mystic:rare_crate_key') continue
    crate_key += item.amount
}
if (crate_key) plr.runCommandAsync(`scoreboard players set @s rarekey ${crate_key}`)
else  plr.runCommandAsync(`scoreboard players set @s rarekey 0`)
#

I'd use the cmd outside of the loop if that's what should be done

safe gust
#

alr thanks