The title says it all. I want to delete a model, but the name varies so I don't want to put :Destory() for every possible outcome. Is there a way I can delete a file type, not the name of it? if i could do script.Parent.Model:Destory(), that would be nice! So is there anyway I could do that?
You can detect the ClassName
of the object, which will find it regardless of the name:
local model = game.Workspace:FindFirstChildWhichIsA("Model") -- Model name does not matter if model then model:Destroy() end
As my comment explains, FindFirstChildWhichIsA()
ignores the model's Name
and instead finds the model directly by ClassName
. Other methods that do this include IsA()
and FindFirstChildOfClass()
.
This is a follow-up to MCAndRobloxUnited's answer. If you wanted to delete all of a certain instance in the workspace you could do this
local descendants = game.Workspace:GetDescendants() for i=1, #descendants do if descendants[i]:IsA("InstanceTypeHere") then descendants[i]:Destroy() end end