for i,v in pairs (game.Workspace:GetChildren()) do if v.Name == "Script" then v.Script:Destroy() end end
how would I get the children twice? Because I'm trying to remove all the scripts under the hats in the model hats.
You really need to be using a recursive function here, because the Model
that you describe may have more than just two levels of children, you should also check if an Instance
is a Script
by using the IsA()
method, rather than seeing if it is called "Script"
.
This will work in the command bar too:
function DeleteScripts(instance) for _,v in pairs(instance:GetChildren()) do if v:IsA("Script") then v:destroy() else DeleteScripts(v) end end end
Then you can use it like this, by passing it the Model
or Instance
that you want the Script
s to be removed from:
DeleteScripts(workspace.Hats) --Insert your object path