I'm trying to figure out an accurate way to determine if an Anchored part is touching any other part. Here is the function I have written so far.
function checkCollisions(part)
local MIN,MAX,RAN,RAD,FLOOR,ROOF = math.min,math.max,math.random,math.rad,math.floor,math.ceil
local pos = part.Position
local size = part.Size
local startpos = Vector3.new(pos.x-size.x/2,pos.y-size.y/2,pos.z-size.z/2)
local endpos = Vector3.new(pos.x+size.x/2,pos.y+size.y/2,pos.z+size.z/2)
local REG3 = Region3.new(Vector3.new(MIN(startpos.X,endpos.X),MIN(startpos.Y,endpos.Y),MIN(startpos.Z,endpos.Z)),Vector3.new(MAX(startpos.X,endpos.X),MAX(startpos.Y,endpos.Y),MAX(startpos.Z,endpos.Z)))
local partsinREG3 = game.Workspace:FindPartsInRegion3(REG3,nil,1)
if #partsinREG3 > 0 and partsinREG3[1].Transparency == 0 then
return partsinREG3[1]
elseif #partsinREG3 < 1 then
print(part.Name..' is not colliding with any other object.')
return false
end
end
It seems fine, but for some reason, it bugs out and sometimes says that their is a part in range when there isn't.

1 comment
I need someone that can tell me how to fix this function because I'm having a good amount of trouble myself.