How detect Part:GetTouchingParts() if Part CanCollide == false?

Hello! I’m making building system, and I need detect some collisions. For that collisions I use 5 walls, which are created around plot. But the problem is in that PreviewPart have CanCollide == false, and walls can’t detect it. Can someone help me, and say, how I can enable collisions for PreviewPart?

1 Like

There are several ways to detect parts ‘colliding’ without requiring them to have CanCollide enabled, but I suppose this should work.

for i, v in next, Part:GetTouchingParts() do
if v.CanCollide == false then
--// Whatever
end
end;

Can you explain me, what next doing, please?

the next() is just iterating through your table, it’s basically the same as pairs().

I believe pairs() uses next(), also if the code sample I’ve provided above solved your problem, remember to select it as the ‘solution’.

1 Like

oh, but there’s exist 1 problem - if part have CanCollide == false it just won’t detect it…
and check

if v.CanCollide == false then
--// Whatever
end

won’t be triggered

Have you tried it already? (chars)

Yes, I’m tried it minute ago. It don’t work.

Then I’d suggest Region3.

local Region = Region3.new(-Part.Size, Part.Size);

for i, v in next, workspace:FindPartsInRegion3(Region3) do
if v.CanCollide == false then
--// Whatever
end;
end;

(may have errors, been awhile since I’ve had to use Region3 and not RotatedRegion lol.

sadly it don’t detect CanCollide == false parts too. =\

How are you checking if they are being detected?, are you using print() in the for loop?

Yes, I’m getting parts in part / region3, and if array lenght > 0 (it find 1+ parts), then it returns false, otherwise it returns true. For each wall test, I print(tostring(#Array) .. " Wall" .. tostring(i). When Part have CanCollide == false, #Array = 0, but if I set CanCollide = true, it works fine.
Stop. Maybe I found solution rn… I’ll try it.

for i, v in next, Part:GetTouchingParts() do
if v.CanCollide == false then
print(v)
end
end;

try this on it’s own.

This won’t return anything with CanCollide off.

Try this method

2 Likes

Please don’t use this anymore, review the solution to that post.

Other thing you cab use is GetPartsInBoundingBox

local List = game:GetPartsInBoundingBox(CFrame,BoxSize,Overlapparams)