So first I took a non-collision part and converted it to a region3. When the function is ran, it goes through all the parts within that region and checks for humanoids. It then adds the characters to a table and then returns that table. For some reason, some players are not detected. `local module = {}

function module.GetCharsFromRegion(part)--converts part to a region local function PartToRegion3(obj) local abs = math.abs

	local cf = obj.CFrame
	local size = obj.Size 
	local sx, sy, sz = size.X, size.Y, size.Z 

	local x, y, z, R00, R01, R02, R10, R11, R12, R20, R21, R22 = cf:components() 

	local wsx = 0.5 * (abs(R00) * sx + abs(R01) * sy + abs(R02) * sz) 
	local wsy = 0.5 * (abs(R10) * sx + abs(R11) * sy + abs(R12) * sz) 
	local wsz = 0.5 * (abs(R20) * sx + abs(R21) * sy + abs(R22) * sz) 

	local minx = x - wsx
	local miny = y - wsy
	local minz = z - wsz

	local maxx = x + wsx
	local maxy = y + wsy
	local maxz = z + wsz

	local minv, maxv = Vector3.new(minx, miny, minz), Vector3.new(maxx, maxy, maxz)
	return Region3.new(minv, maxv)
end

local function findCharsInRegion(region) -- finds chars using part to region
	local parts = workspace:FindPartsInRegion3(region)
	local chars = {}

	local function checkCharList(char) -- ensures there are no duplicates, inserts chars into table
		for _,v in pairs(chars) do
			if v == char then
				return
			end
		end
		table.insert(chars,#chars+1,char)
		return
	end
	for _, v in pairs(parts) do -- loops through all parts found in the region
		if v.Parent:FindFirstChild("Humanoid") then
			local char = v.Parent
			checkCharList(char)
		end
	end
	return chars
end

local charList = findCharsInRegion(PartToRegion3(part))--find chars in region defined by part conversion
return charList

end

return module `

1 comment

0

You don't need such a long script to reach your goal, would you mind me to rewrite it and explain it to you?