Counting near by entitys

How do i count how many entitys are near by.

example:
if i wanted to count the number of bouncy balls nearby and then run something if there is less then 10.

Depending on how nearby you want to check, you could use ents.FindInSphere. For example,


if table.Count(ents.FindInSphere(LocalPlayer():GetPos(),500)) < 10 then RunConsoleCommand("+forward") end