ENT:Use only prints the "else" part of what it is supposed to


	function ENT:Use( activator, caller, useType )

		
                        local _ents = ents.FindInSphere( self:GetPos(), 10000 )
                        for k, v in pairs( _ents ) do
                                
                                if ( v:GetClass() == "simple_nextbot" ) then
			        activator:ChatPrint( "A hostile lifeform has been found!" )
                                else
                                activator:ChatPrint( "Nothing has been found from our search." )
		

	return
	end
	
end
end


You may remember this code from Problems that Don’t Need Their Own Thread, because I had a different question about it. Well, when I spawn my nextbot NPC(it’s class is simple_nextbot") right next to my entity and I press my use key on my ent, it just says “Nothing has been found from our search.” Why is that? Just so you know, I put in “return” so it doesn’t print a wall of text whenever a player uses the entity. Should I place it somewhere else to get the same desired affect, while fixing everything, meanwhile?



function ENT:Use( activator, caller, useType )
	local _ents = ents.FindInSphere( self:GetPos(), 10000 )
	for k, v in pairs( _ents ) do
		if ( v:GetClass() == "simple_nextbot" ) then
			activator:ChatPrint( "A hostile lifeform has been found!" )
			return
		end
	end
	activator:ChatPrint( "Nothing has been found from our search." )
end


because you’re looping through all entities in that code, it’ll run through entities 1 through however many entities you have. if the first entity isn’t your next bot, then the else code would run and the function would stop because you put a ‘return’ there.

so what i did was i made the function look through every entity. if it says the class is a simple nextbot, then it’ll state what you wanted it to and stop the function. if it doesn’t find one, it’ll use the ‘else’ print that you had before.

Thanks! It works now.