0

I'm making a Minecraft virtual market and, here are my commands for command blocks.

First command block: Impulse, Unconditional, Needs Redstone

/tellraw @p {"text":"Succesfully purchase an item","color":"gree n"}

Second command block: Chain, Unconditional, Always Active

/scoreboard players remove @p[distance=..7,scores={money=100..}] money 100

Third command block: Chain, Unconditional, Always Active

/give @p minecraft:golden_apple 1

How do I make another command such that when you run out of money it says say "you don't have enough Money".

2 Answers 2

2

Use /execute if score:

execute if score @p money matches ..99 run tellraw @p "currency deficiency"
execute if score @p money matches 100.. run tellraw @p "purchase made"

Replace the /tellraws with whatever you need to make your machine work.

If you have enough money, you're probably going to want to run multiple commands if the condition passes. The best way to do this would be to use a data pack and set up a function.

Alternatively, you can have one command per step:

execute if score @p money matches 100.. run tellraw @p "purchase made"
execute if score @p money matches 100.. run scoreboard players remove @p money 100

but I do not recommend this, especially if the number of steps increases.

-2

Use /scoreboard players test to check if a player has a high enough score. You'll want to place the test command in an impulse block, then have your current impulse block be a chain pointing to it. Then, place another impulse block to test if the player has less than 100 money, and place a chain block behind it that displays your 'not enough money' message. Connect both the impulse blocks to your redstone circuit so that the test to see if they don't have enough money triggers first. Otherwise, it may complete the transaction then tell the player they don't have enough money because they spent it.

3
  • 2
    Do you have a code to share for me please? or picture
    – Aizen Wong
    Commented Apr 8, 2021 at 7:20
  • @Aizen Wong The code for testing if they have money is "/scoreboard players test @p money 100". For testing if they lack money, it's "/scoreboard players test @p money 0 99". Just put those at the start of the chain of command blocks. Commented Apr 8, 2021 at 10:46
  • 1
    No that only works on Bedrock Edition, this question is for Java edition
    – One 2 Many
    Commented Apr 8, 2021 at 17:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.