/* Bloxd.io Shop Script - Fixed removeItemName Argument Error */
let price = 1; /* Cost in Yen */
let amountToBuy = 1; /* Amount of Dirt given */
/* Look at what the player is currently holding in their hand */
let heldItem = api.getHeldItem(myId);
/* Validate: Holding a Gold Coin AND its name is exactly 'Yen' */
if (heldItem && heldItem.name === "Gold Coin" && heldItem.attributes && heldItem.attributes.customDisplayName === "Yen") {
/* Check if they are holding enough of it */
if (heldItem.amount >= price) {
/* Fixed: Exactly 3 arguments passed to removeItemName */
api.removeItemName(myId, "Gold Coin", price);
/* Attempt to give the player their Dirt */
api.giveItem(myId, "Dirt", amountToBuy);
/* Inventory full safety check */
if (api.inventoryIsFull(myId)) {
/* Refund the exact item layout if their inventory had no space */
api.giveItem(myId, "Gold Coin", price, { customDisplayName: "Yen" });
api.sendMessage(myId, "Your inventory is full! Yen refunded.", { color: "red" });
} else {
api.sendMessage(myId, "Successfully bought " + amountToBuy + " Dirt!", { color: "green" });
}
} else {
api.sendMessage(myId, "You need to hold at least " + price + " Yen in your hand!", { color: "red" });
}
} else {
/* Triggers if they hold normal Gold Coins or an unrelated block */
api.sendMessage(myId, "Please hold your 'Yen' coins in your hand to buy!", { color: "yellow" });
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter