2

The scoreboard I've made is called credits. I want people to have fun and buy items with it, but I've discovered that I can go below 0 with my credits, and that breaks everything because the other commands now interpret me as having unlimited credits now.

How do I make it not go below 0 using commands?

2

Place a repeating command block on the ground and set it to Always Active.

Place this command into it:

scoreboard players set @a[scores={credits=..0}] 0

This command will target everybody whose score is less than 0 and set their score to 0.

| improve this answer | |
1

Every tick, set each the score player with a score less than 0, to 0.

I believe one of these should work:

/scoreboard players set @p[scores={credits=..0}] credits 0

or

/scoreboard players set @p[score_credits=0] credits 0

Run whichever works every tick, try to do it before other tick functions.

Alternatively, you could only deduct credits if the player has more than zero, otherwise set their balance to 0.

Edit: As ExpertCoder14 pointed out, the first one should work.

| improve this answer | |
  • 1
    Ooh, looks like we both got to the same answer at the same time! (For Bedrock Edition, it's the 1st one, by the way. The 2nd is Java Edition 1.12-.) And note that this can go in a repeating command block, because there aren't functions in Bedrock Edition. – ExpertCoder14 Jul 14 at 2:17
  • Also, you can optimize the command by replacing @p with @a. – ExpertCoder14 Jul 14 at 2:20
  • Thanks. Wasn’t sure if Bedrock still used Java’s old system so I included both. – Sam Hill Jul 14 at 2:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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