you exit the function after first iteration of the for loop
Code:
public FindClosesEnemy(entid)
{
new Float:Dist
new Float:maxdistance=4000.0
new indexid=0
for(new i=1;i<=g_iMaxPlayers;i++)
{
if(is_user_alive(i) || is_user_bot(i) && is_valid_ent(i) && can_see_fm(entid, i))
{
Dist = entity_range(entid, i)
if(Dist <= maxdistance)
{
maxdistance=Dist
indexid=i
}
}
}
return (indexid) ? indexid : 0
}