Mute Music GUI Throws Error "Attempt To Call A Nil Value"

I have a muting GUI that is supposed to mute ALL music in the Workspace if it’s playing. Here’s the code.

 local child = game.Workspace:GetChildren()
if child:IsA("Sound") and child.IsPlaying == true then child.Volume = 0
	end
end)

I need help as soon as possible.

1 Like

This is because you’re trying to preform :IsA on a table not an object. You could sort through the objects in Workspace.

  for _,child in pairs (game.Workspace:GetChildren()) do --Loop through everything in workspace
	if child:IsA("Sound") and child.IsPlaying then
		child.Volume = 0
	end
end
1 Like

1 Like

I removed the end) at the bottom of the script as it’s completely unrelated to the block of code sent. You may want to add that back. :slight_smile:

1 Like

You want me to add end) back at the bottom of the script, or you want me to add ) back?

1 Like

Add an end back at the bottom.

Okay, now I want this to mute music on boombox gears. How would I do that?

1 Like

If you would like to disable EVERY sound inside of the game in Workspace, you can replace GetChildren with GetDescendants.

That’s just a local only thing, so yeah.