Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Is there a way to use Part:GetTouchingParts() in a for loop?

In a part of my script, I'm taking parts and their positions and adding them to a list (got that part done) but for some reason when I do

-- example code
for i, v in pairs(part:GetTouchingParts()) do
	print(v.Name)
end

It prints nothing, even when multiple parts are touching it. I would appreciate any help, thanks in advance.

2 comments

0

your example says GetTouchingChildren if that has anything to do with it

0

sorry this was just code i made on the spot for an example

1 answer

✓ Accepted answer

Yes you can use it like that in a loop, infact you can even do ipairs since its a normal table

The reason it doesnt work is because:

If the part itself has CanCollide set to false, then this function will return an empty table UNLESS it has a TouchInterest

see the article on GetTouchingParts()

This discussion is preserved as it was. New answers, comments, and votes are closed.