How can I detect if a player won a round?

I’m trying to find a solution that if a player has won or in other words, the last one standing in a round, how can I detect that?

Any help would be appreciated!!

1 Like

you could insert all of the players into a table, and remove them when they get eliminated. if the length of the table is 1, that player is the winner, and the table is cleared for the next round

3 Likes

Can you please show me an example of what you mean?

You would make a table, and use table.insert to insert players as they perform an action, or something happens.

Here’s what @lxgh1lxy means:

local Players = {}

game.Players.PlayerAdded:Connect(function(Player)
	table.insert(Players, #Players +1, {PlayerName = Player.Name, ['Died'] = false})
	wait(2)
	Player.CharacterAdded:Connect(function(Char)
		Char.Humanoid.Died:Connect(function()
			for i, Plr in pairs(Players) do
				if Player.Name == Plr.PlayerName then
					Plr.Died = true
				end
			end
		end)
	end)
end)

wait(5)

local HaveNotDied = 0
local IsWined = false
local Winer = 'Nil'
while IsWined == false do wait(1)
	for i, Plr in pairs(Players) do
		if Plr.Died == false then
			HaveNotDied = HaveNotDied +1
		end
	end
	if HaveNotDied == 1 then
		for i, Plr in pairs(Players) do
			if Plr.Died == false then
				Winer = Plr.PlayerName
			end
		end
		IsWined = true
	else
		HaveNotDied = 0
	end
end

print(Winer..' Has Won!')
1 Like