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)
This is relatively easy to achieve. I’ll try to break it down for you, but let me know if something needs more clarification.
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 ?)
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)
There were a couple of issues with your code snippet:
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.
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.