Can I reduce the number of parts that need to be considered in this loop?

Greetings,

as this is more of a theoretical question, I will not be including a .rblx file unless somebody requests it.

Here is the current setup,
i got a map made up of (5,1,5) size parts, about 1800 per map, and i got a bomb that explodes and changes the collision group of the parts in a 11 stud radius and their transparency, and to do that i use a for loop that iterates through a folder containing the current map, which is a model.

for i,v in pairs(workspace.CurrentMap:FindFirstChildWhichIsA("Model"):GetChildren()) do

            if v:IsA("BasePart") then

                local Start = Pos
                local End = v.Position

                local Mag = (End - Start).Magnitude

                if Mag <= 11 then 
                    
                    if v.Name ~= "Spawn" then
                        
                        v.Transparency = .75
                        v.CollisionGroupId = 1
                        
                    end
                end
                
            end
        end

it works perfectly, but i am worried that this might be a bad approach? what do you guys think?

just to check something i put in a print in the loop and my game froze for a bit every time the loop ran and printed 1800+ times so i am now worried this is poor design

Ideally i’d like to avoid having to search the whole map and just scan in the radius around the position of the bomb, however i don’t know if that’s even possible let alone how to do it.

Any advise would be greatly appreciated, thank you for your time

Going through all those parts is not an efficient way of doing it. Instead you will want to create a part at the bomb and get all the parts that way.

Here is a way to use a sphere to get all the parts in a radius without effecting physics. This will give you any parts that are inside the sphere (The blast radius) and from there you can do what you need to do with that list.

function GetPartsInRadius(Radius,Position)
   local Sphere = instance.new("Part")
   Sphere.Anchored = true
   Sphere.Shape = "Ball"
   Sphere.Size = Vector3.new(Radius,Radius,Radius)
   Sphere.CanCollide = false
   Sphere.Position = Position
   Sphere.CanCollide = true
   local Touching = Sphere:GetTouchingParts()
   Sphere.CanCollide = false
   Sphere:Destroy()
   
   return Touching -- An Array Of Parts
end