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

Plugin search through EVERY descendant of EVERY descendant and removing certain names?

What I've done is made ONE plugin that makes the shadows into descendants, but I don't know how to remove them again...

Making

--That button and Toolbar stuff
button.Click:connect(function()
button.Click:connect(function()
A = game.Workspace:GetChildren()
for i,v in pairs(A) do
    if v.ClassName == "Model" then
        human = Instance.new("Humanoid") 
        human.Parent = v
		human.Name = "Shadow"
		human.DisplayDistanceType = "None"
    elseif v.ClassName == "Union" then
        human = Instance.new("Humanoid") 
        human.Parent = v
		human.Name = "Shadow"
		human.DisplayDistanceType = "None"
    end
end	
end)

My attempt at removing

--Toolbar and Button stuff
button.Click:connect(function()
A = game.Workspace:GetChildren()
for i,v in pairs(A) do
    if v.ClassName == "Humanoid" and v.Name == "Shadow" then
		v:remove()
    end
end	
end)

Note The Maker does not also go through each descendant, which I also need help with.

1 answer

✓ Accepted answer

Based on your orignal code you're adding 'Shadows' to models and unions who are children of workspace, but I see you want to apply this to all descendants of workspace. An easy way to do that is to write a recursive function.

button.Click:Connect(function()
	function addShadow(obj)
		for i,v in pairs(obj:GetChildren())
			if v:IsA("Union") or v:IsA("Model") then
				local human = Instance.new("Humanoid") 
				 human.Name = "Shadow"
				 human.DisplayDistanceType = "None"
				 human.Parent = v
			end
			addShadow(v) --function calls itself on children of obj making it recursive.
		end
	end	
	addShadow(workspace)	
end) 
-- and then to remove what we added
button.Click:Connect(function()
	function removeShadow(obj)
		for i,v in pairs(obj:GetChildren())
			if v.Name == "Shadow" and v:IsA("Humanoid") then
				v:Destroy()
			end
			removeShadow(v) 
		end
	end
	removeShadow(workspace)		
end) 

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