How would i get all objects in a folder

I know about :GetChildren() and :GetDescendants() if you think i mean every object i just cant explain it but i hope what i say below will help. So i want something like :IsA(“PartObject”) that would return true if it is a object that a players character can touch. So like a base part but all of the other stuff.

3 Likes

You should be using a for loop to get all of the children of the folder and then you can check whether if any child is a Basepart, like this:


for i, v in pairs(Folder:GetChildren()) do
       if v:IsA("BasePart") then
           print(--- print whatever you want)
    end

end

6 Likes

local function makeWeld(weldTo)
	local weldConst = Instance.new("WeldConstraint",rocket.welds)
	weldConst.Part0 = rocket.base
	weldConst.Part1 = weldTo
	return weldConst
end

for i,v in pairs(rocket.rocket:GetDescendants()) do
	makeWeld(v)
end


That is my code but i want to check if its a part that can be welded.

2 Likes

I knew noone would understand what i said :smiley:

1 Like

My only guess here is you’re mistaking a BasePart for a regular Part.
Baseparts cover all object types that have collision, including Wedges, Unions, etc, meaning your problem should already be solved.

2 Likes

Example:

local Folder = script.Parent
local Inside = Folder:GetChildren() -- Assigning a local variable is faster.

for _, Search in ipairs(Inside) do
   if Search:IsA('BasePart') then
      print(Search.Name)
   end
end

ipairs is used for arrays, and GetChildren() returns an array.

5 Likes

Ok litrally noone understands me.

1 Like

I have edited my post, I assume that’s what you are looking for.

1 Like

I looked back and it didnt notify me for some reason but univert solved it by

My only guess here is you’re mistaking a BasePart for a regular Part.
Baseparts cover all object types that have collision, including Wedges, Unions, etc, meaning your problem should already be solved.

2 Likes

Why are you using ipairs? You can use pairs for that and it would work also ipairs is slower than pairs.

1 Like

You should use ipairs over pairs. GetChildren returns an array, ipairs runs quicker and it’s idiomatic for contiguous arrays.
pairs is designed more for a dictionary where your keys aren’t known (noting that it returns next).

Use cases aside, it’s also good for collaborators and being clear as to what part of the table you’re intending to traverse through. I know when I see ipairs I understand that an array is being iterated over.

Reference: Click here.

5 Likes

Okay understandable gonna start using ipairs over pairs now :smiley:

Ok me too :smiley: Again character minimum :frowning: