✓ Accepted answer
The best way is Region3 as you said.
Your method does not work because the region part your script is inside of is not collideable so :GetTouchingParts will return empty table. You could create .Touched event to create the touch interest but that's disgusting.
Regions in Roblox are quite simple, you just specify 2 vectors, TopLeft and BottomRight positions of the region. For comfort you can make the region have same size and position as specified part which will make it easier to use.
local Part = script.Parent
while true do
local Region = Region3.new(
Part.Position - (0.5 * Part.Size),
Part.Position + (0.5 * Part.Size)
)
local TouchingParts = workspace:FindPartsInRegion3(Region, Part, math.huge)
print(TouchingParts)
wait(0.5)
end
The region was created from position and half size of the part? I don't know that math is too complicated for me however it works, just remember that.
:FindPartsInRegion3 is function of workspace which returns table of all parts inside of given region, 2 argument is filter, in this case it will filter Part and all of it's descendants so they won't appear in the table, it can be nil but it's up to you, the third argument is max amount of parts you want to be in the region, i used the hugest number possible but it's up to you again.
###Region3
###FindPartsInRegion3
2 comments
I have just one question, is there a way to add a region3 before running the game, or do I need to create one using a script?
No, the only possible way would be is to create plugin which stores CFrame and Size of the region that you want to create and then use it to create the region, however, not sure if that is usefull.