Is it possible to use scoreboards from NBT number values?

I have this NBT tag on a slimeball: {price:200}.

How would I use /scoreboard players remove or something similar to that to remove coins from a player off of this value price?

So in this case it would remove 200 coins from me, but if I changed this number to something like 1000, it should remove 1000 coins from me.


Solution 1:

You can use the execute store to store the price into a fake's player score and then use the scoreboard operation to remove that quantity.

execute store result score $Price <score name> run data get entity <slime target> <nbt path>
scoreboard players operation <player target> <score name> -= $Price <score name>

Where slime target is a player with the item or the item on ground itself.

A fake player is just a username that can't be registered using special chars like $ or #. This way we make sure our system will never use a real player name and it makes it more readable.