Step 1: Place this command in a Repeat command block and set it to Always Active
execute as @a if entity @s[x=63,y=22,z=-815,dx=0,dy=0,dz=0] run function comandos:spawnpoint1
This command checks if any player is at the specified coordinates and executes a command — in this case, a function.
Just change the coordinates as needed (press F3 to see). As for the function being executed with run, I’ll explain it now:
The function allows you to run a set of commands at once, meaning you can execute 2, 3, 4 or more commands together.
Step 2: To create your function, check out this tutorial here if you're not familiar with the process.
Download the ready and complete function by clicking here and place it inside the datapacks folder
Here are the commands used in my function:
execute if score @s checkpoint matches 0 run spawnpoint @s 63 22 -815 -90
Note: If the command above doesn't work, add a 0 at the end. The -90 and 0 correspond to the X and Y rotation, respectively.
execute if score @s checkpoint matches 0 run tellraw @s [{"text":"Checkpoint reached!","color":"green"}]
execute if score @s checkpoint matches 0 run scoreboard players set @s checkpoint 1
First, we check if the player's score in the checkpoint objective is equal to 0. If it is, the commands are executed.
Since we haven’t set any score yet, it will be 0, and the spawnpoint and tellraw commands will run.
Finally, we set the player’s score to 1 so that the checkpoint doesn’t trigger again.
This last command is mandatory to avoid infinite execution.
Step 3: Place 2 Impulse command blocks side by side with a button and add the following two commands:
One command creates the scoreboard objective, and the other gives players a starting score of 0.
This prevents the command from looping, since no score is set by default.
scoreboard objectives add checkpoint dummy
scoreboard players set @a checkpoint 0
Step 4: Now test it! Press the button created in Step 3 to set up the scoreboards.
Then, go to the coordinates to check if the commands are executed successfully.