I have a question for round systems

How can I detect a player when they died and kick them out of a round? Let’s say like a round system.

Depends on what round system you have implemented but one way is once the round starts, gather the players that are being placed into the round and use:

local players_in_round = {} -- list of players in the round

for _,player in ipairs(players_in_round) do
   local humanoid = player.Character and player.Character:FindFirstChildOfClass("Humanoid")
   if humanoid then
      humanoid.Died:Connect(function()
           -- this player has died, boot them off the round list
      end)
   end
end
1 Like

How would I go about when the player died?

That’s where Humanoid.Died comes in. When a player dies, it’s their humanoid that’s being killed off. So the event Humanoid.Died will fire off once their character fully dies. So if you implement your round system, you should have a lobby list. Before starting the round, iterate through that list and attach this connection to each player’s humanoid such as the code described. It’s an example but without knowing how you’re implementing your round system I can’t help much but that’s the basic.

  1. Get the Player instance.
  2. Get their Humanoid, if exists.
  3. Connect their .Died event to a function that will take them off the round, whatever that means for your game.

I can’t create a script for you because you didn’t leave even an attempt, but I can leave some ideas for you.

  1. When the round starts (after intermission), put all players into a table.
  2. When the player dies, remove them from the table.
  3. Every second you can check the amount of players inside the table life #PlayerTable.
  4. If there’s only one player in the table, end the game.

Oh, I understand, just thanking you for how I can approach this idea.

So instead of using a table to list my players, I used a bool value. I’m just wondering how would I use the “Humanoid.Died” event in my script. Also, if you see any mistakes or anything I should change please tell me. (It would be nice if someone can format my script cause Idk how.) This is all in one script.

game.Players.PlayerAdded:Connect(function(player)
local Died = Instance.new(“BoolValue”)
Died.Value = false
Died.Parent = player

if #game.Players:GetPlayers() >= 2 then
	print("enough players")
end

end)

while wait() do
	for i,Plr in pairs(game.Players:GetPlayers()) do
		local Humanoid = Plr.Character:FindFirstChild("Humanoid")
		if Humanoid then
			Humanoid.Died:Connect(function()
			--Need help here

           end)
		end
	end
end

You don’t want to connect it multiple times because each time you connect it it will fire. Which means once the player dies, it will fire as many times as you connected (which could be thousands of times with that loop :shock: ). So by the looks of your first script you could implement it like this:

game.Players.PlayerAdded:Connect(function (player)
   ...
   if #game.Players:GetPlayers() >= 2 then
      -- set up the round or whatever
      
      -- create a list of all the current players in the
      -- server.  These players will be in the round.  New
      -- players that join the server hereafter will be
      -- excluded from the round because they are not on the
      -- list
      local playersInRound = game.Players:GetPlayers()

      -- now we can iterate through playerlist and connect
      for i,P in ipairs (playersInRound) do
         local humanoid = P.Character and P.Character:FindFirstChildOfClass("Humanoid")
         if humanoid then
            humanoid.Died:Connect(function ()
               local idx = table.find(playersInRound, P)
               if idx then
                  table.remove(playersInRound, idx)
               end
            end)
         else
            table.remove(playersInRound, i) -- remove because they haven't spawned in yet
         end
      end
   end
end)