Last man standing and ending the game

trying to get the round to end whenever everyone of one of the two playing teams are empty but its not working

code:

				if v ~= Juggernaut then
					if Survivors[v] == true then
						Survivors[v] = nil
					end
				else
					if v.TeamColor == BrickColor.new("Persimmon") then
						Status.Value = "Survivors Win!"
						wait(5)
						break
					end
				end
			end
			
			if #Survivors <= 0 then
				Status.Value = "Juggernaut Wins!"
				wait(5)
				break
			end

When you set the survivor to nil, it does not actually remove the index from the Survivors table. Therefore, whenever you use the # operator on the table, it returns the number of players that are in the table, regardless of if they have died or not. In order to do this, remove indices via table.remove(Survivors,v); this is given that v is a number, however I can not tell without seeing the top code. If v is a string or non-number index, you can use table.find to obtain the numeral index.

Table documentation can be found here.

Hope this helps! :slight_smile:

  • MattPrograms
1 Like