Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Children Of Children?

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.

1 comment

0

Running in command bar btw.

1 answer

✓ Accepted answer

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

2 comments

0

Thank you sir!

0

It was my pleasure, YellowTide! :)

This discussion is preserved as it was. New answers, comments, and votes are closed.