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

How do I use region3 to find parts?

Sorry if this is a dumb question but I can't seem to be able to get region3 to work. I am trying to find parts near a certain position, however I cannot figure out how to do this using region3. Here is my attempt:

while true do wait (1)
	local list = {workspace.Folder}


	 region = Region3.new(script.Parent.Position,Vector3.new(400,400,400)) -- position, size right?

	local parts = workspace:FindPartsInRegion3WithWhiteList(region, list, 1000)
	for i = 1, #parts do

	print(parts[i].Name)
	end

	print("the script is running")

end

There is a part descended from "Folder" right next to the script's parent but the script does not detect it. I have absolutely no idea how to use region3s so the problem is probably something really obvious. thanks in advance :)

1 answer

✓ Accepted answer

Region3 gets parts in a region, not parts near a region. With FindPartsInRegion3WithWhiteList, it'd get all parts that are in the Whitelist and only those parts. Using the GetChildren() method on your folder would turn that into the correct data. I used this to get the correct min and max for the Part you're setting the region for.

local WhiteList = workspace:WaitForChild("Folder"):GetChildren()
local Root = script.Parent.Parent
local Min, Max = Root.Position - (0.5 * Root.Size) , Root.Position + (0.5 * Root.Size)
local Region = Region3.new(Min, Max)
while true do 
	wait (1)
	local parts = workspace:FindPartsInRegion3WithWhiteList(Region, WhiteList, math.huge)
	for i,v in pairs(parts) do 
		print ( i,v )
	end
end

1 comment

0

thx

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