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)
