TransWikia.com

How do I execute a command if only one player is present on a scoreboard

Arqade Asked by Dat guy on February 26, 2021

I’m playing on bedrock and I’m making a UHC map. I have a scoreboard set up where it lists everyone still alive, and once people die they get taken off the scoreboard. I want a command to test when only one person is left on the scoreboard. This last survivor would be the winner and I would like to have a title appear when they win.

For my UHC I have a repeating command block setting the players spawn point inside an enclosed bedrock box. When the player dies and spawns in this box, they land on a pressure plate resetting their score on the alive scoreboard, hence taking their name off the display. After their score is reset, the are teleported into a room where they have the option to spectate.

2 Answers

Use this command /execute store result score players playerCount if entity @e[type=player,scores={deaths=0..0}] what this will do is store the amount of players in a scoreboard. Make sure to add playerCount as a scoreboard

Answered by C0deRed on February 26, 2021

The current answer has the right idea, but wrong execution for bedrock.

Adjust your current scoreboard so every player on it has a value of one.

/scoreboard objectives add alive dummy
/scoreboard players set @a alive 1

Create a variable to hold the total.

/scoreboard objectives add alive_total dummy

When players respawn on the pressure plate, reset their score.

/scoreboard players reset @p[r=2] alive

Have a repeating command block chain with the following commands:

/scoreboard players set total alive_total 0
/scoreboard players operation total alive_total += @a alive
/scoreboard players test total alive_total 1 1

Then chain the logic you want to run at the end of that command chain. Be sure to make the chain conditional.

Answered by peabody on February 26, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP