Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I get all the parts in model including descendants of model?

I want to get every non-collideable objects in workspace. However, It won't work because CanCollide is not a property of Model. How do I fix this problem?

local ignore = {}
local Collision = game.Workspace:GetDescendants()
for index, Collision in pairs(Collision) do
	if Collision.CanCollide == false then
		table.insert(ignore, Collision)
	end
end

1 comment

0

check if Collision is a BasePart first before doing it

1 answer

All Roblox instances have a member function object:IsA(className) which returns true if the object is of or inherits the class className. false otherwise.

For example, BasePart is the superclass of classes such as Part, MeshPart, and ect. These classes inherit from BasePart.

Also consider a better variable name rather than "Collision". Not every child will be a part.

local ignore = {}
local children = game.Workspace:GetDescendants()

for _, child in ipairs(children) do
    if child:IsA("BasePart") and not child.CanCollide then -- == false not needed
        table.insert(ignore, child)
    end
end

Is child an inheritor of BasePart?

Check if the part has collisions disabled

If it does, insert them into the ignore table

2 comments

0

if it does, not it does u nerd!

0

no u

This discussion is preserved as it was. New answers, comments, and votes are closed.