How would i make a Volume limit in a sound

btw Use hb:wait() instead of wait() (unreliable)

e.x

local g = game.GetService
local r = g(game,"RunService")
local hb = r.Heartbeat
while hb:wait()  do
if not script.Parent:FindFirstChild("Sound") then return end
if script.Parent.Sound.PlaybackLoudness > 500 then script.Parent.Sound:Stop(); break end
end
1 Like

I think so too i learned heart beat in this topic and i was searching this for long time thankssss

1 Like

Better yet if you don’t want to slow your game down by running this every frame you can connect a property changed signal to PlaybackLoudness.

1 Like

Could i have a an example on this too. I want to try every method i can.

script.Parent.Sound:GetPropertyChangedSignal(“PlaybackLoudness”):Connect(function()
if script.Parent.Sound.PlaybackLoudness > 500 then script.Parent.Sound:Stop() end
end

like that

local sound = //Insert sound location
sound:GetPropertyChangedSignal(“PlaybackLoudness”):Connect(function()
if script.Parent.Sound.PlaybackLoudness > 500 then
sound:Stop()
end
end)
1 Like

No, get property changed signal returns an event that fires every time that the property changes.

1 Like

This didnt work, i havent tried the others.

Also, I’d recommend making a message appear on the player’s screen when you stop the audio as some players will get confused on why their audio stopped randomly.

And if you want to limit audio volume, I’m working on a system in my spare time that will allow you to do this.

Interesting, are you sure the audio you tested goes over the limit?

I put the limit to 5 to test that out still doesnt work.

Can you put a print in front of where you test if the audio is too loud.

This is to test that the event is firing.

When it plays i check the property’s and it says 0 any reason why?

Note that this property is NotReplicated you’ll have to check the property on the device that started the sound. Also the property doesn’t change when using studio’s sound preview system.

Even when im in game it doesnt work.

Are you on the server when checking the value.

Still 0.

(Character limit 30.)

Connect a RunService.Heartbeat connection and check the PlaybackLoudness property.

Also you’ll need to do this on the client.

local RunService = game:GetService('RunService')

RunService.Heartbeat:Connect(function()
    if audio.PlaybackLoudness >= 500 and not audio.IsPaused then
        audio:Pause()
    elseif audio.IsPaused then
        audio:Resume()
    end
end)

This example would pause the volume if the PlaybackLoudness is 500 or higher until it decreases.

If this works my script should work too but just only on the client. To prevent exploiters a majority rules system may need to be added.