When a chosen player dies, the round ends

I’ve literally looked around everywhere. I can’t find a single solution to this. What I am trying to do is find if the player is the chosen player when they die. If they are It turns the chosenPlayer Value to nil.

Heres the code:

connections[player.Name] = player.Character.Humanoid.Died:Connect(function()	
				table.remove(playersInRound, table.find(playersInRound, player))
				table.remove(playerInRoundNames, table.find(playerInRoundNames, player.Name))
				if not table.find(playersInRound, ChosenPlayer)then
					ChosenPlayer = nil
				end
			end)
ChosenPlayer = playersInRound[math.random(1, #playersInRound)]

To begin with, why this?

connections[player.Name] = player.Character.Humanoid.Died:Connect(function()	

If you’re doing PlayerAdded, all you need to do is:

Player.Character.Humanoid.Died:Connect(function()

The beginning is pointless, unless it’s needed in your code and we can’t see for whatever reason, i.e you not sharing nor wanting to share, or it being non exclusive to the question.

May you elaborate on any errors in the output?

There are no errors in the output, but for some reason when the chosen player dies. Its value never gets set to nil.

Assuming you put player names in the table and not player object, you would need to do player.Name inside of table.find(), I believe.

1 Like

Lets say I did put the player object inside table, would i need to change it to player names?

1 Like

Well it’s best to stick with Player’s name anyways
Here’s why:
You could do both, but you’d need to call the entire variable, “game.Players.Mischiefing”

1 Like

No, once the humanoid dies the first time the event won’t fire anymore since the humanoid will be reloaded. You need to create a connection every time the character is added.

He uses it in a table to disconnect old connections that are useless.

1 Like

Stop worrying about the other code, what I’m trying to do is have a chosen player. And there are other players in this round. When this chosen player dies… the round ends, even if other players are still alive.