How to cancel Event:Wait() in a while loop

So i am trying to make a deathmatchsystem (the script is server side) and the script below should check if a player dies it removes the player from the table until 1 player is remaining.

The problem is there is a limited time in this deathmatch and the DMV.Value is the timer-active value located in ReplicatedStorage

It changes through another timer script from the server.

But the while loop continues and nothing below the while loop doesn’t executes…

		while DMV.Value == true do
			while #DrawPlayers ~= 1 do
				
				local player = Hdied.Event:Wait() --Player Died
				
				print(player)
				local e = table.find(DrawPlayers, player) --Checks if player is one of the DrawPlayers
				if e then
					table.remove(DrawPlayers, e)	
				end
			end
			DMV.Value = false
		end
1 Like

When does this happen?

1 Like

I recommend restructuring this to use :Connect instead of the while loop like this:

Hdied.Event:Connect(function(player)
	print(player)
	local e = table.find(DrawPlayers, player)
	if e then
		table.remove(DrawPlayers, e)
	end
end)
1 Like

but if there are 3 players it can go only once and i need to make it to only 1 player in the table (its in a function btw)

so the while loop should end if the last player remains and it doesn’t end.
Draw players is the table of the players btw