[SOLVED] Checking for parts using Region3

Hello! Recently I made a mining system that creates parts whenever you destroy other parts.

As you can see in the video, it doesn’t really work that well, because it takes a lot of time to detect new parts (since I save all of the part’s positions, every new part forces the script to look through hundreds of others, which takes time)

I was thinking of creating a Region3 to detect parts, something like this:

I’m just not sure how I would detect anything?
If anyone can help, it will be greatly appreciated!

What about using mouse.target and check if it has an boolean that it’s mineable?

That’s what I currently use. I also save all block’s location in a folder in serverstorage, and look for them everytime to check if they are there, which causes the block overlap, I heard a region3 small check could do the thing, idk how to do it though

You don’t need that, just make a boolean value to check if it exists

yeah but after they destroy it, I don’t want parts to still be spawning there

What does the code that handles checking previous locations and spawning new minerals look like? I’m guessing (mostly based off what was shown) you’re aiming for a system that dynamically loads in blocks around the player as they’re revealed (rather than generating it all at once)?

1 Like

If the part has collisions disabled this Region3 area will represent the area taken up by the part in the workspace.

local part = workspace:WaitForChild("Part")
local region = Region3.new(part.Position - part.Size/2, part.Position + part.Size/2)
1 Like

So if I understand this correctly, the problem is that when you mine a block, it might cause a new block to spawn in a loaded block? In that case, you should save your blocks in a 3D table. This way, you will be able to index the blocks variable, which is much faster than an iterative approach. You should not try to get through a locked door with brute force when you simply have the key at your disposal.

// Pseudo code (actual code will look differently, but this will give you an idea)
if blocks[x][y][z] then
   // The block already exists
end

https://developer.roblox.com/en-us/api-reference/function/WorldRoot/FindPartsInRegion3

1 Like