I’m trying to use region3 as an alternative to .Touched as .Touched seems to not be able to detect an object quickly entering and exiting it.
The region3 I’ve set up does not work though, and I’m not experienced enough with it to know why. Here is my code for the region3:
local Goal1 = Region3.new(workspace.Goals.Goal1.P1.Position,workspace.Goals.Goal1.P2.Position)
local Goal2 = Region3.new(workspace.Goals.Goal2.P1.Position,workspace.Goals.Goal2.P2.Position)
local regions = {Goal1, Goal2}
while task.wait() do
for i, region in pairs(regions) do
local parts = workspace:FindPartsInRegion3(region)
for _,v in pairs(parts) do
print(v)
end
end
end
The only parts it detects seems to be very large parts.
I most likely have found a solution to your problem.
To first understand how Region3’s actually work, I highly recommend to read the ROBLOX API about anything first. It has a lot to offer.
To actually create a Region3, you have two components (the min and max boundaries). I assume you want a system as if it were simulating the .Touched event ROBLOX gives us. To do this, the Vector3 boundaries can be calculated as below.
local region = Region3.new(part.Position-(part.Size/2), part.Position+(part.Size/2))
Here’s a visual representation of the goal and the boundaries below:
These boundaries are used to simulate the whole part itself, but as a Region3.
After revising the code a little bit, everything seems fine and the only problem was how the Region3 was calculated. Here is the code that should work:
local goals = {
workspace.Goals.Goal1;
workspace.Goals.Goal2
}
local regions = {}
for _, goal in pairs(goals) do
local region = Region3.new(goal.Position-(goal.Size/2), goal.Position+(goal.Size/2))
table.insert(regions, region)
end
while task.wait() do
for i, region in pairs(regions) do
local parts = workspace:FindPartsInRegion3(region)
for _, v in pairs(parts) do
print(v)
end
end
end
Make sure to mark this post as solution if it helped you!