Anti Earrape Script
Key RequiredUniversal

Anti Earrape Script

Universal ScriptWeavyWeavy 26.6K views 11 executesUpdated Oct 22, 2023
5.0/ 5(1 votes)
10100% Positive
Lua Script•67 lines (1484 chars)
--[[
    Updated By Weavy
]]

local RunService = game:GetService("RunService")
local SoundThreshold = 700 -- Modify it to your liking [700 = default]

local originalVolumes = {}
local activeSounds = {}

local function muteSound(sound)
   if not originalVolumes[sound] then
       originalVolumes[sound] = sound.Volume
   end
   sound.Volume = 0
end

local function restoreSound(sound)
   if originalVolumes[sound] then
       sound.Volume = originalVolumes[sound]
       originalVolumes[sound] = nil
   end
end

local function updateSounds()
   for _, sound in ipairs(activeSounds) do
       if sound.PlaybackLoudness > SoundThreshold then
           muteSound(sound)
       else
           restoreSound(sound)
       end
   end
end

local function onSoundAdded(sound)
   table.insert(activeSounds, sound)
end

local function onSoundRemoved(sound)
   for i, activeSound in ipairs(activeSounds) do
       if activeSound == sound then
           table.remove(activeSounds, i)
           restoreSound(sound)
           break
       end
   end
end

for _, sound in ipairs(game:GetDescendants()) do
   if sound:IsA("Sound") then
       onSoundAdded(sound)
   end
end

game.DescendantAdded:Connect(function(descendant)
   if descendant:IsA("Sound") then
       onSoundAdded(descendant)
   end
end)

game.DescendantRemoving:Connect(function(descendant)
   if descendant:IsA("Sound") then
       onSoundRemoved(descendant)
   end
end)

RunService.Heartbeat:Connect(updateSounds) -- Initialize

Features & Information

Basically tracks every sound instance in your game and if their PlaybackLoudness goes over the threshold will temporarily mute it until the sound maintains below the threshold. Made By: Empire4946 Updated By: Weavy
#Script#keyless#universal

Community Comments (0)

No comments yet for this script.

More Scripts for Universal Scripts