How to make a ringing noise on death?

Basically when the player dies I want a ringing noise to play and muffle every other sound in the game until the player respawns again. I’ve tried going to run the game and copy the oof noise to change it but im just not that good at scripting.

I was able to play the ringing noise on death, although the hard task was to find the right configurations to “muffle” every in-game sound. What I ended up doing was combining the UnderWater AmbientReverb with an EqualizerSoundEffect:

--LocalScript inside StarterPlayerScripts
local SoundService = game:GetService("SoundService") 

--The LocalScript runs inside Player.PlayerScripts
local Player = script.Parent.Parent 

--path to the ringing sound
local RingingSound = script:WaitForChild("RingingSound")

--caching the added effects, the active connections and the old reverb to revert the changes on respawn
local effects = {} 
local connections = {} 
local oldReverb = SoundService.AmbientReverb --default reverb

function muffleSound(sound) 
	local eq = Instance.new("EqualizerSoundEffect")
	--you can expirament with the gain properties for better results
	eq.HighGain = -8
	eq.MidGain = -20 
	eq.LowGain = 0 
	eq.Parent = sound 
	table.insert(effects, eq)
end

function muffleSoundsOf(parent) 
	local function objectAdded(object) 
		if not object:IsA("Sound") then return end 
		muffleSound(object)
	end
	--looping through current sounds
	for _, object in pairs(parent:GetDescendants()) do 
		objectAdded(object)
	end
	--listening for new sounds being created(so new sounds also have the effect)
	local connection = parent.DescendantAdded:Connect(objectAdded)
	table.insert(connections, connection)
end

function Enable() 
	RingingSound:Play() 
	oldReverb = SoundService.AmbientReverb 
	SoundService.AmbientReverb = Enum.ReverbType.UnderWater 
	--very expensive, can be optimized depending on the game behavior
	muffleSoundsOf(workspace) 
	muffleSoundsOf(SoundService)
	muffleSoundsOf(Player.PlayerGui) 
end

--Reverting the changes
function Disable() 
	RingingSound:Stop() 
	SoundService.AmbientReverb = oldReverb 
	for _, effect in pairs(effects) do 
		effect:Destroy() 
	end
	effects = {} 
	for _, connection in pairs(connections) do 
		connection:Disconnect() 
	end
	connections = {} 
end

--CharacterAdded runs every time the player respawns
function CharacterAdded(character) 
	Disable() 
	local Humanoid = character:WaitForChild("Humanoid") 
	Humanoid.Died:Connect(Enable) 
end

CharacterAdded(Player.Character or Player.CharacterAdded:Wait()) 
Player.CharacterAdded:Connect(CharacterAdded)

Working result: Death sound ringing - Roblox

3 Likes

Thanks alot! It works perfectly as intended!

1 Like

Hey there, this has got nothing to do with “On death” but is there any way I could make the disable function occur after 10 seconds?

Humanoid.Died:Connect(function()
	Enable()
	task.wait(10)
	Disable()
end)

and also remove the Disable() line at the top of the CharacterAdded function.

1 Like