[Help] Grabbing the Number of Players in a Specified Range as an Integer

Just what the title says, I’m trying to grab the number of players in a specified range radial around the player as an integer. I’ve already got the radial search set up, I just don’t know which hook/function to use to translate the number of players as an integer.

Any help is appreciated.

What is your radial search currently returning? A table?

Yeah, a table of specified entities that includes things like missiles, players and vehicles. The search function already sorts players out to draw a dot on the radar for them, but I want to count how many of the dots it’s drawing so that I can display that as an integer on the HUD.

So the table that you have from your search function, you need to iterate through it and for each entry check to see if it is a player (ENT:IsPlayer()) and if so then have a playerCount variable that you increment for each player.

local function GetPlayersByRadius(vector, radius)
	local playerTable = {}
	for k, v in pairs(ents.FindInSphere(vector, radius)) do
		if (v:IsPlayer()) then
			table.insert(playerTable, v)
	return playerTable

local function GetNumberOfPlayersByRadius(vector, radius)
	return #GetPlayersByRadius(vector, radius)