Hello. How could I make it so whenever an audio reaches a certain loudness a part becomes visible. Thank you!
I believe sounds have a Loudness property that you can read and simply check if it’s greater than a certain number every period of time
If you mind could you explain more in depth please?
You could run a loop such as a RenderStepped (RunService) loop and check if the Loudness property of the SoundObject is greater than the number that you want the part to show (basically a threshold)
Alright I don’t understand fully but thanks for the help
This is probally very wrong but this isn’t working? I thought this would do it (inside starterplayerscripts)
local sound = game.Workspace.Bar.Sound
local maxLoudness = 30
local amplitude = math.clamp(sound.PlaybackLoudness / maxLoudness, 0, 1)
local part = game.Workspace.Bar
if amplitude then
part.Transparency = .5
part.CanCollide = true
else
part.Transparency = 1
part.CanCollide = false
end
It’s because you are defining the amplitude
at the beginning
local bar = workspace:WaitForChild("Bar")
local sound = bar:WaitForChild("Sound")
local maxLoudness = 30
sound:GetPropertyChangedSignal("PlaybackLoudness"):Connect(function()
local amplitude = math.round(math.clamp(sound.PlaybackLoudness / maxLoudness, 0, 1))
if amplitude == 1 then
bar.Transparency = .5
bar.CanCollide = true
elseif amplitude == 0 then
bar.Transparency = 1
bar.CanCollide = false
end
end)
Make sure the sound instance is being played locally too (from a local script).
You can do that by writing something like this this:
local part = [replace with your part here]
local sound = part.Sound
local thresholdVolume = 5 -- replace with the desired break-over point for when the sound becomes loud enough
sound.Changed:Connect(function()
if sound.Volume >= thresholdVolume then
part.Transparency = 0
end
end)
this does not make it visible. I set the maxloudness to .5 and the reg volume for the sound is at 2
You replied to me yet quoted the other person’s script. Also isn’t max loudness 30 as seen in your original script?
I guess I assumed you wanted it to be higher when the part is visible. Just change the >=
operator to <=
and it should be fine.
Sorry it was wrong c&p I meant your script
I used the formula you had provided, the part will only show if the MaxLoudness property reaches 15 or above.
local bar = workspace:WaitForChild("Bar")
local sound = bar:WaitForChild("Sound")
sound:GetPropertyChangedSignal("PlaybackLoudness"):Connect(function()
if sound.PlaybackLoudness > 0 then
bar.Transparency = .5
bar.CanCollide = true
elseif sound.PlaybackLoudness <= 0 then
bar.Transparency = 1
bar.CanCollide = false
end
end)
I’ve removed the formula and just made it so that the part shows if the sound is playing and can be heard. PlaybackLoudness doesn’t replicate so make sure the sound is being played locally as well.
This is not working. My script is inside starterplayerscripts and it obv local.
I’m not sure if you wanted me to make the sound get louder as time goes on but I wrote this so if it is past a certain volume it will make a part invisible.
MaxLoudness = .5
sound = game.Workspace.Bar:WaitForChild("Sound")
part = game.Workspace:WaitForChild("Bar")
while true do
wait(0.1)
if sound.Volume >=MaxLoudness then
part.Transparency = 1
end
end
I’m not referring to the script in this thread, I’m referring to whatever script is playing the sound.
I need it so it is only visible if the volume is only a certain volume. I just assume I would change the > to <. Sorry I’ve just never worked with this stuff
The “PlaybackLoudness” property shared by Sound instances does not replicate across the client/server boundary, that means that if you play the song locally (from a local script) and attempt to check the property’s value from a server script it will display as 0, similarly if you play the song from a server script and attempt to record the property’s value from a local script it will also be displayed as 0. The script playing the Sound instance needs to be the same class type as the script which is checking the property. You can use print() commands to debug.