How do I check to see if all players who are in-game have died (leaving one alive)?

  1. I want to check if all players who are in the game have died once

  2. This is my first game, and I cannot find a round tutorial on youtube with this feature. A search on this forum also turned up nothing, surprisingly.

  3. Nothing

An idea I have is to check total players at the start of the round and store that as an IntValue in ReplicatedStorage and subtract whenever a player dies?

No, because players in the lobby could reset character to make the round stop before there is only one player left.

Yeah, I really have no clue

Update: I’ve created the variable and workingly set it to currentplayers at the start of each round.

Here’s some potential solutions. Note that there are multiple ways that you can attack this from, and it’s ultimately up to you to make the solution that you feel best.

  1. Using a BoolValue system that gets checked whenever Humanoid.Died is fired. This would limit your list and make debugging in Studio fairly easier, but also will take up more resources.
  2. Use a table to store player IDs and mark them as true when they die (using the same Humanoid.Died event). Takes up less resources than using BoolValues, but less easy to see what’s going on if you need to debug. Works the same functionally as BoolValues though.
  3. Use Attributes to see whether a Player has died or not (again, using the same Humanoid.Died event). Again, functionally the same as the previous two options.

I think I’ve given a few options for you to choose from - the important part is to use the Humanoid.Died event to see when a Player dies, and to store that relevant information. As for your other issue, using StarterGui:SetCore might be able to help you. You can actually disable the reset button behavior (ResetButtonCallback) by using SetCore (along with a whole host of other default Roblox buttons if you want to configure those).

2 Likes

Thanks. I just implemented that setcore because I could figure it out.

You could store your players in a dictionary and check if they died and behave accordingly.

There exist a myriad of ways to resolve this, ObjectValues, Attributes and Tables, sorted in ascending performance order.

local Bool = Instance.new("BoolValue") --Whenever a player's character is added place a 'BoolValue' inside the player.
Bool.Value = true --'true' indicates that the player is alive.
Bool.Parent = Player

local function OnDied()
	Bool.Value = false --Switch the value to 'false' indicating that the player has died.
end
Player:SetAttribute("Alive", true) --Set an attribute of any name (preferably an accurate one) which indicates that the player is alive.

local function OnDied()
	Player:SetAttribute("Alive", false) --Switch the attribute's value to 'false' or 'nil' indicating that they have died.
end
local Alive = {} --Array that'll store alive players.
table.insert(Alive, Player) --Insert the player into the array of alive players.

local function OnDied()
	table.remove(Alive, table.find(Alive, Player)) --Remove the player from the array when they die.
end
1 Like