Help with strange results from ent:think() and ents.getall() player.getAll()

So I am making a mod to a tool i like very much called NPC Spawn Plateform 2.2

I wanted to make it so the npcs the platform spawns only do so if a player is within 2000 units.

well it works, but it only works for me and it wont trigger for any other players.

PS. please note I have tried player.GetAll() and I have tried find in sphere ( find in sphere had odd broken results too )

here is the code: found in the init.lua of the platform entity of the spawn platformer.



function ENT:Think()
	if (self.Spawned < 0) then self.Spawned = 0 end
	if (self._WireSpawnedActive) then
		Wire_TriggerOutput(self,  "OnNPCSpawned",  0);
		self._WireSpawnedActive = nil;
	end
	
	for k, v in pairs(ents.GetAll()) do // please note I have tried player.GetAll() and I have tried find in sphere ( find in sphere had odd broken results too )
	
		if v:IsValid() and v:IsPlayer() then
			
			if(v:GetPos():Distance(self:GetPos()) < 2000) and self.Spawned < self.k_maximum and self.LastSpawn + self.k_delay < CurTime() then
			self:SpawnOne();
			else
				return
			end
		 
		end
		
	end
	
	

end


Looks like as soon as it finds a player that doesnt satisfy that condition it returns, which will halt the loop from continuing any more players. Try replacing return with ‘continue’.

I’ll try that but I don’t see why in a think function and player.GetAll() if player < x units then spawn a zombie doesn’t work for any players other than the server owner.

( because all players that are alive and not crashed should be valid )

I did not think that this would work, but I tried it out several times now and I think it is working.

thanks for the input Foohy.