Struggling with Region3

I’m using Region3 to create something similar to the Minecraft building system. It works fine (for a few seconds) and then broke. “Broke” here means it doesn’t ignore parts that are mentioned in the array anymore. It seems like an engine bug (but I could be stupid :slight_smile:).
Here’s my script:

local region = Region3.new(blockPosition - Vector3.new(1.9, 1.4, 1.9), blockPosition + Vector3.new(1.9, 1.4, 1.9))
local parts = workspace:FindPartsInRegion3WithIgnoreList(region, {unpack(game.Workspace.Parts:GetChildren()), result.Instance, game.Workspace.Baseplate, script.Parent.Handle, unpack(game.Workspace.Blocks:GetChildren())}, 500)
print(#parts, unpack(parts)) -- also prints object stored in the "ignoreObjects" parameter
if #parts == 0 --[[this way of checking looks unefficient, you can give some suggestions on it, too]] then
-- do something
end

Frankly, I’ve tried nothing :slight_smile: because I don’t know where to start.

1 Like

You are checking the number of parts only for 1 time and the table returned will return the instances in that region for the time it checked and not get updated.
Instead use a game loop to check every frame if there is something in that region.

local region = Region3.new(blockPosition - Vector3.new(1.9, 1.4, 1.9), blockPosition + Vector3.new(1.9, 1.4, 1.9))
game.RunService.Heartbeat:Connect(function()
    local parts =   workspace:FindPartsInRegion3WithIgnoreList(region, {unpack(game.Workspace.Parts:GetChildren()), result.Instance, game.Workspace.Baseplate, script.Parent.Handle, unpack(game.Workspace.Blocks:GetChildren())}, 500)
    if (#parts == 0) then
        print("LuaU") 
    end 
end)

Using Hearbeat assuming it is from a server script.

Sincerely sorry for not writing the topic clearly. The function is triggered by an event, but I thought that event wasn’t important so I didn’t added it in my script section. And also, this script is a local script (because I’m trying to achieve a lag-free building system).

1 Like

Oh wait, it’s not true that I’ve tried anything, I’ve tried making a separate array then placing that variable in the “ignoreObjects” parameter. However, this way is obviously useless (because it is the same as putting the array itself in the parameter) so let’s just assume I’ve tried anything :slight_smile:.

I would suggest using: workspace:GetPartBoundsInBox, GetPartsInRegion3 is depricated.
I could find a exact explenation on it, this is the best I found.

1 Like

I just tried that, but it still doesn’t work. I think, somehow, my array is wrong, although I can’t find any errors in it.
Edit: I’ve just tried printing “unpack(game.Workspace.Parts:GetChildren()” folder and it only outputs 1 part (name). I found the problem but still doesn’t know how to fix it so the main question now is “What is WRONG with ‘unpack(game.Workspace.Parts:GetChildren())’?”
More helpful info: There’s a line where the parts stored in that folder is parented, that line has no error at all (probably it looks so obvious that I can’t notice the error).

This could be a solution.
The folder is not replicated so my local script can’t detect objects in it, maybe. Therefore, a possible solution would be putting the folders in the “ReplicatedStorage”.
Edit: I’m being dum again, I forgot that putting parts in the “ReplicatedStorage” wouldn’t display them in the 3D world.

try:

if parts[1] then
--run code
end

or

if not parts[1] then
--run code
end 

Sorry for not replying sooner, but I think that way is just the same as using “#parts == 0”, maybe. If I am wrong, can you state the benefits of “parts[1]” over “#parts == 0”, because I’m dum :slight_smile:.

I read this already :slight_smile:. However, the problem isn’t about the Region3 (although the topic is “Struggling with Region3”), the unpacking of this “game.Workspace.Parts:GetChildren()” table seems wrong (it only prints out 1 part but the folder has more). This could be an engine bug or I’m just using it wrong (by the way, I just know about the “unpack()” function yesterday :slight_smile:).

Haven’t used region3, but if it uses a table like OverlapParams do to filter the instances, I think you gotta manually update it with the new instances you add.

so for example:

local Folder = workspace.Parts
local PartRange = ((Block.Size).Magnitude / 3) --Change for your range

local OverParams = OverlapParams.new()
OverParams.MaxParts = -1 --Infinite
OverParams.FilterType = Enum.RaycastFilterType.Whitelist
OverParams.FilterDescendantsInstances = {Folder}

local parts = workspace:GetPartBoundsInRadius(BlockPosition, PartRange, OverParams)
if #parts == 0 then
--do something
OverParams.FilterDescendantsInstances = {Folder} --Update table
end

Thanks, but I think the problem is at unpacking the folder (“Parts” folder) because when I printed out the children of that folder, the output only showed one element. Even so, when I use the command bar to do the same thing, it outputs out the whole folder. I don’t know why.

There isn’t realy a benefit, I’m just used to using that.

Ok, but thanks anyway. As for my problem, I solved it by using a for loop to add items into the “ignoreTable” instead of unpacking folders because the “unpack()” function seems to be broken :slight_smile:.

Nice!

Good luck with your projects!