How to See If Two Parts Are Touching

Hey fellow scripters! I wanted to make a system where if two parts were touching, they would snap together like Legos! I do not know how to do this, and I have tried looking through the dev forum, but I could not find anything that fits my needs. Thank you in advance, and let me know if you need anything more from me!

You can just use the Touched event of BaseParts:
https://create.roblox.com/docs/reference/engine/classes/BasePart#Touched

Depending on your specific use case, you can also look at raycasting.

1 Like

So when I try to do that it is required that one part is anchored but I want to be able to use a drag detector to drag the parts around. When I drag the anchored part it does not have the physics of the unanchored part that I want.


[Anchored part dragged first, and unanchored dragged second]

edit: nvm i’m stupid lmao, reread what you wanted. i’ll try to find a different solution

WAIT

You could anchor a part when it’s not being dragged. Does your envisioned system have any reason why that wouldn’t work?

1 Like

YES I JUST THOUGHT OF THAT :joy:

1 Like

I just realized that I could just anchor the part once it is placed so then the next piece is touching the anchored part!

1 Like

Hey i have a question. So if I am trying to make a lego brick connecting type thing where should I put the script that handles if the parts touch?

Try out CollectionService

1 Like

So would I make a collection service and then make a script where it applies to every part with that collection?

You don’t “make” a collection service—it’s a service, like Workspace or ServerStorage.

What you can do, is add a tag to your bricks, like Snappable or something idk. Then, you can use CollectionService to get every Instance that has this tag.

1 Like

Ok thank you! Lol I am not very experienced with the advanced services or anything really :joy:

1 Like

If you want the docs for collection service, the blue text I sent is actually a link to it.

@asher_dz

1 Like

Thank you! I will use it!

1 Like

Don’t hesitate to ping me (@Microwave_Toothpaste) if you need any more help.

1 Like

Thank you for being so helpful! I really appreciate it!!!

1 Like