How do I remove a child by defining it with GetChildren?

Using GetChildren(), I’m attempting to remove an equalization effect that I’ve generated under all of the sounds in workspace.

This is what I’ve tried so far:

for i,v in pairs (game.Workspace:GetChildren()) do
				if v:IsA("Sound") then
					for effects in pairs(v:GetChildren()) do
						local EqualizerSoundEffects = v:GetChildren()
						if EqualizerSoundEffects:IsA("EqualizerSoundEffect") then
							EqualizerSoundEffects:Destroy()
						end
					end
				end
			end

Why can’t you just use GetDescendants() instead of having to use nested loops?

for i, v in pairs(workspace:GetDescendants()) do
    if v:IsA("EqualizerSoundEffect") then
        v:Destroy()
    end
end

Another thing is that you could provide us a bit more information on what error is occurring :thinking:

2 Likes

I’m trying to find the equalizer effect that’s under the sounds, so I’m trying to make a for loop to find the sound, and then check for the equalizer effect to destroy it.

use :GetDescendants() then

for i, v in pairs(workspace:GetDescendants()) do
      if v:IsA("EqualizerSoundEffect") then
             v:Destroy()
      end
end

Why not just do

if v.Parent and v:IsA("EqualizerSoundEffect") and v.Parent:IsA("Sound") then

If you want to check if the Equalizer’s Parent is a Sound as well? I might have it mixed up though

This will work, thank you and @Jackscarlett for helping me figure it out, sometimes common sense doesn’t cross my mind lol.

Well be sure to mark one of our answers as solution so others can see it more easily

1 Like