I want to be able to destroy a mesh from everything in a model, and I find it inefficient to erase the mesh manually by doing each part individually. Is there any way I can do it in 1 line, or a few lines? The meshes are all named the same thing.
This will work.
EXAMPLE:
local Model = game.LocationOfWhereTheModelIs.Model:GetChildren() for i, v in pairs(Model) do if v:IsA(Mesh) or v.Name == "Name of the part" then v:Destroy() else return false end end
You can change the or in the if statement to and if you want both conditions to be true to continue with the code.
You can use a for loop, conditional statements, and :GetDescendants() like what Char187 said to destroy certain objects in your model.
Here is how you would do it :
local model = game.Workspace.SomeModel for i,v in pairs(model:GetDescendants()) do if v.Name == "MeshIWantToDestroy" then v:Destroy() end end
So as you can see, the script is getting everything under the "model" with the for loop and :GetDescendants(). The script finds anything named "ModelIWantToDestroy" and destroys it. If you have multiple meshes with different names though, you can instead use the statement if v:IsA("BaseMesh") then
, which find anything in the model that is a mesh (There are multiple types of meshes, so I put "BaseMesh". I don’t know if that exists though).
Hoped this helped, and sorry if my code explanation is a little long. :P