#[RESOLVED] Why doesn't my code work?

1 messages · Page 1 of 1 (latest)

visual cliff
#

Does anyone know why my script doesn't detect the player's game mode? It worked fine a few versions ago, but now I'm losing durability even in creative xD

export function decreaseDurability(player, item, amount) {
    if (amount <= 0) return;
    const durability = item?.getComponent("durability");
    const unbreakingLevel = item.getComponent('enchantable')?.getEnchantment('unbreaking')?.level;

    if (player?.getGameMode() !== "creative") {
        if ((durability.maxDurability - durability.damage) > amount) {
            if (!unbreakingLevel) {
                durability.damage += amount;
                player.getComponent("equippable")?.setEquipment("Mainhand", item);
            } else {
                if (Math.floor(Math.random() * (unbreakingLevel + 1)) == 0) {
                    durability.damage += amount;
                    player.getComponent("equippable")?.setEquipment("Mainhand", item);
                }
            }
        } else {
            player.playSound('random.break');
            player.getComponent("equippable")?.setEquipment("Mainhand", undefined);
        }
    }
};

-# (I'm using version 2.0.0 in the manifest although I don't know if it has anything to do with it)

spring burrow
#

Maybe try to import GameMode enums to use, in case they like changed case or something?

#

Idk what script version you're using but I just looked at a few of mine and the ones that work (lol) use "Creative" - capital C will do it for ya

visual cliff
#

Well, I fixed it now. Apparently the problem is because I had put "creative" instead of "Creative" emoji_14