Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 8 years ago

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

Log in to vote
2
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
8 years ago

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
0
This looks like it will work for me, thanks! xolbStudios 127 — 8y
Ad

Answer this question