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.
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 Scripts to be removed from:
DeleteScripts(workspace.Hats) --Insert your object path
Thank you sir!
It was my pleasure, YellowTide! :)
This discussion is preserved as it was. New answers, comments, and votes are closed.
1 comment
Running in command bar btw.