Scoreboards

Scoreboards track numeric values for players and entities. They're one of the two runtime variable containers in a datapack (the other being data storage), and are essential for game mechanics, timers, and counters. If you're unsure when to use a scoreboard versus a Kotlin variable, read Runtime Logic first. For the full scoreboard command reference, see Commands.

You can manage scoreboards with the scoreboard command:

scoreboard.objectives.add("my_objective", ScoreboardCriteria.DUMMY)
Kotlin

Creating objectives

You have multiple forms of the scoreboard command:

scoreboard {
	objectives {
		add("my_objective", ScoreboardCriteria.DUMMY)
		// this form lets you manage multiple objectives at once
	}
}

scoreboard {
	objective("my_objective") {
		add(ScoreboardCriteria.DUMMY)
		// this form lets you manage a single objective
	}
}
Kotlin

Managing objectives

You can add, remove, set display name, set display slot, set render type of objectives:

scoreboard {
	objective("my_objective") {
		add(ScoreboardCriteria.DUMMY, displayName = textComponent("My Objective", Color.GOLD))
		setDisplaySlot(DisplaySlots.sidebar)
		setRenderType(RenderType.INTEGER)
	}
}
Kotlin

Manage players

You can manage players with the players block:

scoreboard {
	players {
		add(allPlayers(), "my_objective", 1)
		remove(self(), "my_objective", 5)
		reset(self(), "my_objective")
		set(self(), "my_objective", 10)

		operation(self(), "my_objective", Operation.ADD, self(), "my_objective")
	}

	player(self()) {
		add("my_objective", 1)
		remove("my_objective", 5)
		reset("my_objective")
		set("my_objective", 10)

		operation("my_objective", Operation.ADD, self(), "my_objective")
	}
}
Kotlin

You can also manage an objective for multiple selectors at once:

scoreboard {
	players {
		objective("my_objective") {
			add(self(), 1)
			remove(self(), 5)
			reset(self())
			set(self(), 10)

			operation(self(), Operation.ADD, self(), objective)
		}
	}
}
Kotlin

Or also manage an objective for a single selector:

scoreboard {
	player(self()) {
		objective("my_objective") {
			add(1)
			remove(5)
			reset()
			set(10)

			operation(Operation.ADD, self(), objective)
		}
	}
}
Kotlin

These methods offer a more readable way to manage objectives, and avoid repetition operations invoking multiple times the same selector/objective.

To show custom text lines on the right of the screen, like on servers, use the Sidebars helper from the helpers module.