Suitable Spawns

Okay, so I’ve been trying to make this code that would detect if an enemy is near a spawnpoint or not. The problem is that it doesn’t work. When a suitable spawn is available, then it just makes them respawn in the last position that they died, however it works just fine without the suitable spawn code. Could anyone help me figure out how to make this work properly? Is it because I’m using table.Add instead of table.Merge or something different? I don’t know that much about tables so it’s kinda hard to get it working for me.


function GM:PlayerSelectSpawn( usr )
	local spawn_name="info_player_rebel"
	if(usr:Team()==2)then spawn_name="info_player_combine" end
	local spawns = ents.FindByClass( spawn_name )
 --Get all the props in the map
	local suitable = {} 
	for _,sp in pairs(spawns) do
		local IsSuitable = true
		if(GAMEMODE:IsSpawnpointSuitable( usr, sp, false))then
			IsSuitable=false
		else
			for k, v in pairs(ents.FindInSphere(sp:GetPos() , 700)) do
				if(v:GetClass()=="player")then
					if(v:Team()!=usr:Team()) then
						IsSuitable=false
					elseif(v:Team()==usr:Team()&&usr:GetPos():Distance(v:GetPos())<=80)then
						IsSuitable=false
					end
				end
			end
		end
		if(IsSuitable==true)then
			if(sp!= nil)then
				table.Add(suitable,sp)
			end
		end
	end
	
    
    local random_entry = math.random(#spawns)
	if(suitable != {})then
		random_entry = math.random(#suitable)
		print("Suitable Spawn Found!")
		return suitable[random_entry]
	else
		print("Forcing Rough Spawn")
	end
    return spawns[random_entry]
 
end