How to find part in a certain range

I’m trying to make an AI that can walk around and auto collect objects.

However though, the game has separate sides and it wants to try to walk through a wall, which is impossible.

Is there a way to get the objects are in a certain position of x and z? I don’t really know how to explain it, but I want it to collect objects that are in range of a certain x and z.

Please search before posting

Try to atleast read his post a bit more before posting too.
You can loop through the object and see if the positions are in a range of your x and desired z

local objects = [..]:GetChildren()
local MIN_Z, MAX_Z = 5, 50
local MIN_X, MAX_X = 6, 60

for _, object in next, objects do
     local position = object.Position
     if position.X >= MIN_X and position.X <= MAX_X then
          if position.Z >= MIN_Z and position.Z <= MAX_Z then
            
          end
     end
end
3 Likes

I did read it.

Then you would’ve realized that he wasn’t talking about shortest distance (magnitude), but getting objects within a certain position range.

2 Likes