How can i magnitude multiple parts at the same time?

So i’ve been trying to magnitude multiple parts with a simple script.

How can i do it? Any ideas?

thanks.

You might wanna wrap that in a while loop in order to constantly keep checking for the magnitude.

for i, v in pairs(partsFolder:GetChildren()) do
    if v:IsA("BasePart") then
        if (obj.Position - v.Position).Magnitude <= 10 then
            --do whatever you want
        end
    end
end
1 Like

That’s a very broad question. If they are in a table, you can loop through them, like this:

for i, v in pairs(partsParent:GetChildren()) do
--Magnitude check to v
end

What exactly is your goal? To find the closest part, or something else?

Edit: @rokec123’s solution will run for every part within 10 studs.

2 Likes

Hello, thank you for your help. I tried this out and it did work correctly. :slightly_smiling_face:

Thank you, I were trying to find the closest part, still @rokec123 solution works for me fine and is what i need right now. :slightly_smiling_face:

1 Like