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

How do i check if a part is NOT inside of a Region3?

Asked by 4 years ago

I've made a simple script that should detect if a part is not inside of a Region3 but i've realized that if the part is not inside the Region3, it will not trigger the script. Does anyone know any solutions or workarounds to this problem?

local regionPart = game.Workspace.RegionPart
local pos1 = (regionPart.Position - regionPart.Size/2)
local pos2 = (regionPart.Position + regionPart.Size/2)
local region = Region3.new(pos1, pos2)
local Preview = script.Parent:WaitForChild("Preview")


while true do
    wait(1)
    local partsInRegion = workspace:FindPartsInRegion3WithWhiteList(region,{Preview},100)
    for i, part in pairs (partsInRegion) do
        if part ~= nil then
            print("Blueprint is in region")
        else
            print("Blueprint is not in region")
            Preview.Position = game.Workspace.DefaultCenter.Position
        end
    end
end

Answer this question