Inside a model there are more models and every one of them has a part called "Main". Every part must be close enough to at least one other part.
for _, model in ipairs(mainModel:GetChildren()) do closeEnough = false checkFor = model:WaitForChild("Main") for _, model2 in ipairs(mainModel:GetChildren()) do checkWith = model2:WaitForChild("Main") if <checkFor is closer to checkWith than 4 studs> then closeEnough = true end end if not closeEnough then script:Destroy() end end
Obviously, I also check if checkFor~=checkWith, but I didn't include that here.
What I want to know is, how to check the distance between two parts, and if there is a more efficient way to do what I'm trying to accoplish.
To find the distance between two points, you just use the distance formula, which you've probably covered in math class. On roblox, though, they give us a property that does most of the math for us, called magnitude.
(b.Position - a.Position).magnitude
That will give you the distance between the points. You should be able to implement it in your code pretty easily.