How do I add a sound effect to the whole game?

  1. What do you want to achieve?
    I want to add a certain sound effect to the whole game.
    In other words, let’s say I wanna add a EqualizerSoundEffect to the whole game.

  2. What is the issue?
    I don’t know if that’s possible, and I’m pretty sure doing game:GetDescendants() will lag the game.

  3. What solutions have you tried so far?
    Well, looping through all game descendants isn’t efficient…

Okay, so basically I just wanna make it so I could add a sound effect to every single sound in the game.
Let’s say I wanna make the whole game sound distorted, or maybe I wanna add a EqualizerSoundEffect to the whole game.
How would I do that?
Is that even possible?

Thanks for reading :slight_smile:

Sound | Roblox Creator Documentation s are global if they aren’t parented to a Part, just the workspace.

CollectionService may help reduce the amount of wasted loops:

local CollectionService = game:GetService("CollectionService")

function AddTag(object, tag)
	CollectionService:AddTag(object, tag)
end

function Retrieve(tag)
	return CollectionService:GetTagged(tag)
end

--looping through the entire game, and tagging the objects for the first time
for _, service in pairs(game:GetChildren()) do 
	pcall(function()
		for _, object in pairs(service:GetDescendants()) do 
			if object:IsA("Sound") then AddTag(object, "Music") end
		end
		--To make it update:
		--[[
		service.DescendantAdded:Connect(function(object)
			if object:IsA("Sound") then AddTag(object, "Music") end
		end)
		]]
	end)
end

local eq = Instance.new("EqualizerSoundEffect")
--setting properties of eq here

for _, sound in pairs(Retrieve("Music")) do 
	eq:Clone().Parent = sound 
end

This way the game:GetDescendants() function will only run at the start of the game to tag the objects, and then you have to manually add the tag “Music” to each new sound a script adds to the game(which can be helpful when it comes to organizing a music/club related game).

Forgot I can check for new instances getting added…