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
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
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.
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
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
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)