How can I enable a muffle effect on multiple sounds by touching a part

I’m trying to achieve on making all the sounds muffle when I collide with a part.

What I tried but didn’t work:

local part = script.Parent
local sounds = workspace.Speaker:GetChildren()
local muffle = sounds.Muffle
part.Touched:Connect(function(Hit)
	
		if Hit.Parent:FindFirstChild("Humanoid") == true then
			
		muffle.Enabled = true
		
		end
	
end)

Where are your sounds being stored? What is sounds.Muffle?

1 Like

the sounds are the children of a part called “Speaker” inside workspace

This is relatively easy to achieve. I’ll try to break it down for you, but let me know if something needs more clarification.

  1. Inside every audio you want muffled, insert an EqualizerSoundEffect. Play around with the high, mid and low gains until you achieve your desired muffle effect. (Start with a -20 high gain ?)
  2. When the part is touched, iterate through every audio, check for the EqualizerSoundEffect object and enable it.
local part = script.Parent
local sounds = workspace.Speaker:GetChildren()

part.Touched:Connect(function(hit)
    local humanoid = hit.Parent:FindFirstChild("Humanoid")
    if humanoid then
        for _, sound in pairs(sounds) do
            if sound:IsA("Sound") then
                -- Check if the sound already has an EqualizerSoundEffect
                local muffleEffect = sound:FindFirstChildOfClass("EqualizerSoundEffect")
                if muffleEffect then
                   muffleEffect.Enabled = true
                end
            end
        end
    end
end)

It worked, thanks. Do you know what was wrong with my code? I’m trying to improve on scripting so if you can tell me that will be helpful.

There were a couple of issues with your code snippet:

  1. Accessing Children of workspace.Speaker:

    • You are trying to access children of workspace.Speaker directly using workspace.Speaker:GetChildren(). However, GetChildren() returns a list of objects, and you need to iterate through them to find the specific sound you want.
  2. Accessing muffle Object:

    • The issue with sounds.Muffle is that Muffle is not a property of the Sound object. Instead, you need to manually create or simulate the effect you want. We did this by inserting an Equalizer effect and utilizing that to achieve the desired effect.

Overall though, you had the right idea, especially with how to trigger it! :smiley:

Thanks for taking the time to tell me :pray:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.