--values
local isfound = false
local foundpart
local debounce = false
local cellfound
--
function findtestparts()
local offset = Vector3.new(5,2,5)
local r3 = Region3.new(script.Parent.Position - offset,script.Parent.Position + offset)
local found = workspace:FindPartsInRegion3(r3,script.Parent,5)
local box = Instance.new("Part")
box.Parent = game.Workspace
box.Anchored = true
box.CanCollide = false
box.Transparency = 0.7
box.Position = script.Parent.Position
box.Size = r3.Size
for _, p in next, found do
if p.Name == "TestPart" then
print("TestPart Found")
end
end
end
while true do
wait(0.3)
findtestparts()
end
I wanted to change some values inside parts that are inside a region but I was having problems getting it to work, so I created this test to see what was going on and it appears that region3 is creating problems:
region3 keeps making copies of itself and I dont know how to delete region3’s
when the center part moves next to another part its supposed to detect it but it either detects it once and then its done, or not detect it at all.
could someone help me use region3 properly for the purpose of getting parts around other parts?
The reason why a new region3 is created is because you are creating the region every time that you call the function. The only reason you would need to do this is if the part that you are using the region for is moving.
Try this:
local Region = Region3.new(script.Parent.Position - offset,script.Parent.Position + offset)
game:GetService('RunService').RenderStepped:Connect(function()
for _,Part in pairs(game.Workspace:FindPartsInRegion3(Region,script.Parent,math.huge)) do
if Part.Name == "TestPart" then
print(Part.Name.." found")
end
end
end)
the problem is that your generating your region in the loop change your code to this:
--values
local isfound = false
local foundpart
local debounce = false
local cellfound
local found
--
function createRegion()
local offset = Vector3.new(5,2,5)
local r3 = Region3.new(script.Parent.Position - offset,script.Parent.Position + offset)
found = workspace:FindPartsInRegion3(r3,script.Parent,5)
local box = Instance.new("Part")
box.Parent = game.Workspace
box.Anchored = true
box.CanCollide = false
box.Transparency = 0.7
box.Position = script.Parent.Position
box.Size = r3.Size
end
function findtestparts()
for _, p in next, found do
if p.Name == "TestPart" then
print("TestPart Found")
end
end
end
createRegion()
while true do
findtestparts()
wait(0.3)
end
My solution works in a local script because I am using renderstepped.
If you want something that is Moving, I would not use Region3 as it will get a bit messy, I would use Touched and GetTouchingParts instead, here is an example.
function createRegion()
local offset = Vector3.new(5,2,5)
local r3 = Region3.new(script.Parent.Position - offset,script.Parent.Position + offset)
found = workspace:FindPartsInRegion3(r3,script.Parent,5)
box = Instance.new("Part")
box.Parent = game.Workspace
box.Anchored = true
box.CanCollide = false
box.Transparency = 0.7
box.Position = script.Parent.Position
box.Size = r3.Size
end
createRegion()
box.Touched:Connect(function()
local Parts = box:GetTouchingParts()
for _,Part in pairs(Parts) do
if Part.Name == "TestPart" then
print(Part.Name.." found")
end
end
end)
the problem with using gettouchingparts, is I would have to make an invisible part to collect parts that are inside of it, this would have been my go-to, but I also use the mouse to create buildings and this would cause problems with it. this is why I was hoping to use region3.
I once asked a question on here asking how npcs on vesteria are able to “sense” things around them. the solution to that was region3.
ALSO: I noticed in the wiki that region3 also has a CFrame property, could I perhaps utilize this?
im gonna tell you what my goal is so maybe you can get a better picture on what im doing.
the current project I am working on is sort of an organism simulator were you place cells around to form a bigger organism. buildable models follow the mouse which means I cant use GetTouchingParts() as it would disrupt it. the problem with region3 lies in an unanchored cell that gets pushed along some parts with their velocity set to their lookvector.
the cell needs to be able to deliver oxygen(increasing values) to other cells that surround it as it passes by them.
using region3 means I can avoid mouse problems and accomplish my goal.
Knowing this information, I would try using the CFrame and see if it works, and if not as a last case scenario I would add a blacklist to GetTouchingParts() so that it ignores any parts that you don’t want it to detect and have it update constantly instead of on a .Touched event.
As far as I know, region3s cannot be moved, have you checked similar posts to see if anyone else has tried moving them with success? If that doesn’t work I would maybe try contacting the Vestaria developers in external communications to see how they do it, since you want to replicate their system, usually people are helpful.
I think Im just gonna fire several rays using raycasting to substitute region3. but thanks for your help on this topic. do I need to mark anything as the answer or should I leave it the way as it is?