How would I make a 'noise meter'?

The title says pretty much it all.

How would I make a noise meter(not asking for the whole script, but an idea of how to achieve it)? I’ve thought of PlaybackLoudness, but I couldn’t imagine a way of using it

Here’s a exemple of what a ‘noise meter’ is:

maybe use remoteevents or remote functions?

also what game is that?

2 Likes

Try experimenting with this property of sound. Maybe experiment by using prints to see if it works.


Im not sure if this will work, im also learning like u too lol.
Edit: looks like roblox has already did what u were thinking of, here’s the link to it: Sound.PlaybackLoudness

3 Likes

You should use PlaybackLoudness combined with how far each sound in the game is from the player. You can then see which sounds are closer and adjust the percentage that affects the total count.

1 Like

The game is called Mr. Hopp’s Playhouse 2

ok thanks

lol im probably gonna get banned cuz of off topic related rules

Thanks mods!

1 Like

Maybe have a value change when a sound plays? Not sure if this is an amazing solution. It would allow you to have custom values for each sound the player makes

Example (might be incorrect):

noiseMeter.Value += 5
sound.Playing = true

you’ll be fine, don’t worry about it

Here’s a bit of pseudocode to help you out:

local player = PLAYER_INSTANCE_HERE -- put player here
local totalCount = 0 -- average volume in area
local minDistanceFade = 10 -- distance in studs when the sound starts "fading"
local maxDistanceFade = 25 -- distance in studs when the sound stops "fading" and is "silent"
local sounds = {}

local f = function()
    for _, v in ipairs(workspace:GetDescendants()) do -- expensive, yes
        if v:IsA("Sound") then
            table.insert(sounds, v)
        end
    end

    for _, v in ipairs(game.SoundService:GetDescendants()) do -- expensive, yes
        if v:IsA("Sound") then
            table.insert(sounds, v)
        end
    end

    for _, v in ipairs(sounds) do
        local distance
        if v.Parent == game.SoundService then
            distance = 0
        else
            distance = (v.Parent.Position - player.Character.HumanoidRootPart.Position).magnitude
        end
        local effect = 0
        if distance >= 0 and distance <= minDistanceFade then
            effect += v.PlaybackLoudness
        elseif distance > minDistanceFade  and distance <= maxDistanceFade then
            local result = (distance - minDistanceFade) / (maxDistanceFade - minDistanceFade)
            if result >= 0 then effect += v.PlaybackLoudness * result end
        end
        totalCount += effect
    end

    totalCount /= #sounds -- to average it out
end

coroutine.wrap(function()
    while wait(2) do
        f()
    end
end)()

-- Use totalCount here

I might release this under #resources if it actually works lol

3 Likes
local volume
game:GetService("RunService").Heartbeat:Connect(function()
   for _, v in pairs(game:GetDescendants()) do
       if v:IsA("Sound") then
           volume += v.PlaybackLoudness
       end
   end
end)