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
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