How can I add display names with spaces on the scoreboard? [duplicate]

You could join the 'fake' players in a team that has a custom prefix/suffix so that you don't need to use an underscore/hyphen. Here's an example:

# Add a team, modify its prefix option, then join the `SMP` fake player in it
team add 15SMP

team modify 15SMP prefix {"text": "15 "}

scoreboard players set SMP <objective> 2

team join 15SMP SMP

This should now display the SMP 'fake' player as 15 SMP in the <objective> scoreboard objective


Notice the synopsis of the scoreboard add command:

scoreboard objectives add <objective> <criterion> [<displayName>]

It has an optional <displayName> argument, that can be used to set custom, user-friendly names. While <objective> argument must be a unique, one-word identifier, you can set the <displayName> to anything you want.

In order to use spaces in the <displayName> argument, surround it in quotation marks:

/scoreboard objectives add objective1 dummy "Name with spaces"

You can then check it with:

/scoreboard objectives setdisplay sidebar objective1
/scoreboard players set @s objective1 1

EDIT: I noticed you are using the identifiers with spaces in the scoreboard players command as well. Setting display names or using spaces in these identifiers isn't allowed in Java Edition, unfortunately. It is possible only in the Bedrock Edition, as BE uses generic strings as identifiers, whereas JE does not. However, eggohito brought up a neat trick that can circumvent that in their answer!