How to use get touching parts

how to use get touching parts, or any other ways to detect touches with examples, thanks (:

3 Likes

I’m pretty sure it gets a table so you need to do something like this

local part = script.Parent:GetTouchingParts
for i=1, #part do
part[i]:Destroy
end
3 Likes

:GetTouchingParts literally just returns a table of all of the parts that are touching a certain parts.

Lets say you want to destroy all of the touching parts of a object, you have write something like what @ImTheBuildGuy wrote

yes i get that, but isnt that gonna be very laggy?

local touchingParts = part:GetTouchingParts() --gets a table of touching parts
for _, v in pairs(touchingParts) do -- loops through all the touching parts
    print(v.Name)
end

It shouldn’t be.

9 Likes

GetTouchingParts returns a table of all the BasePart’s touching a part, so you can loop through all of the parts and do something with it.

local mainPart = script.Parent

for _, part in ipairs(mainPart:GetTouchingParts()) do
    print(part.Name, "is touching", mainPart.Name.."!")
end
3 Likes

mk bcuz i wanted to use table.find but it lagged alot

GetTouchingParts can be expensive if used in RenderStepped, which can block the rendering of a frame, or used on a BasePart covering a large area. At that point you should look for alternative.

how would you usually go about checking if hit has something or its brick color is changed? in a reliable way, ofc