How do I make my Scoreboard not fall below 0? MCPE 1.6

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?


Solution 1:

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.

Solution 2:

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.