Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

What's a better way of finding all of the parts/unionoperations in a certain area?

After learning how to use Region3 efficiently, I realized it is greatly limited. It can only return 20 parts at max! Is there a more efficient way to find ALL the parts in a region? I'm not looking for someone to "fix" my script, I'm looking for a method or a solution to my problem. Thanks!

My code utilizing Region3

function drawRegion(Start,End)
	return Region3.new(
		Vector3.new(
			math.min(Start.X,End.X),
			math.min(Start.Y,End.Y),
			math.min(Start.Z,End.Z)
		),
		Vector3.new(
			math.max(Start.X,End.X),
			math.max(Start.Y,End.Y),
			math.max(Start.Z,End.Z)
		)
	)	
end

1 answer

✓ Accepted answer

FindPartsInRegion3/FindPartsInRegion3WithIgnoreList can return up to 100 parts; the default is 20. If you want to get more, repeat the operation while adding everything found to the ignore list until nothing more is found.

function getParts(Start,End)
	local region=drawRegion(Start,End)
	local found={}
	while true do
		local list=workspace:FindPartsInRegion3WithIgnoreList(region,found,100)
		if #list==0 then break end
		for i=1,#list do
			found[#found+1]=list[i]
		end
	end
	return found
end

1 comment

0

This looks like it will work for me, thanks!

This discussion is preserved as it was. New answers, comments, and votes are closed.