New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

How do I use region3 to find parts?

Asked by
OBenjOne 163
12 days ago

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

Log in to vote
1
Answered by
Azarth 2741 Moderation Voter Community Moderator
12 days ago

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
0
thx OBenjOne 163 — 12d
Ad

Answer this question