How do I make special commands run depending on a scoreboard and clock?



  • My friends and I are making a arena minigame where you fight to the death. I want to make it so that after thirty seconds (600 ticks), you get an ender pearl, and once you use the ender pearl, the timer goes back down to zero and you get another one after another thirty seconds. However, I have gotten stuck at the part where the player gets the ender pearl. Here's what I'm doing so far:

    scoreboard objectives add Natan dummy
    scoreboard objectives add NatanSuper dummy
    scoreboard players add @a NatanSuper 1
    execute if score 321nathango Natan >= 1 and if score 321nathango NatanSuper >= 600 NatanSuper run give 321nathango ender_pearl{display:{Name:'{"text":"Natan Super - Ender Pearl","color":"gold","bold":true,"italic":true}'},Enchantments:[{}]} 1
    

    Note: Natan is intended to be an objective name, not a scoreholder. This is because Natan is a pickable role from a list of different characters, each having their own abilities and timers, hence having different objectives.

    I am trying to make it so that it only gives it to you after the 600 ticks pass AND you have the 'Natan' scoreboard greater than or equal to 1. By the way, 321nathango is my username that I am using for testing. It appears that even manually setting my scores to 1 and 600, nothing is happening.

    Does anyone know what might be wrong?



  • The problem is in your last command, specifically this part:

    execute if score 321nathango Natan >= 1 and if score 321nathango NatanSuper >= 600 NatanSuper run
    

    The issue here is that you picked >=. You notice that at this point, you have six options: <, , =, >, >=, and matches. What they don't tell you is that the first five choices are for comparing one score with another score, not for comparing a score with a constant number.

    This means that you are checking if the player 321nathango's [Natan] score is greater than or equal to the player 1's [and] score. It's treating the words 1 and as a player name and objective name respectively, so it's trying to look up another score, specifically the objective named and (which doesn't exist), and the player named 1.

    If you want to compare a score with a constant number, use matches instead: this will allow you to enter a number instead of another player name and objective.

    execute if score 321nathango Natan matches 1
    

    And if you're curious how to do other comparisons other than a direct number match, that's done thru range notation:

    • 5: exactly 5
    • 5..: 5 or more
    • ..5: 5 or less
    • 5..10: 5 to 10



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2