Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by
Neon_N 104
5 years ago

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
0
check if Collision is a BasePart first before doing it DeceptiveCaster 3761 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago
Edited by Gey4Jesus69 5 years ago

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

0
if it does, not it does u nerd! Gey4Jesus69 2705 — 5y
0
no u User#24403 69 — 5y
Ad

Answer this question