Basically what the title says, a MaxVolume value for sounds!
Basically I have some scripts in my game that calculate the soundvolume based on a part’s velocity, but sometimes that part can “spazz out” and go really fast making the calculated volume go up to 2 and causing a massive ear explosion for users.
Now I know this can be done by script (If sound.volume >= 1 etc.) but wouldn’t it be nice to have a MaxVolume value for sounds, just like there’s a MaxDistance value? I would love to see this happening.
I re-calculate the sound every (0.1) seconds for a group of sounds, while also throttling them not to go over a certain volume in the code itself, but this seems to increase the script activity
Here’s an example, I don’t think I’m doing it efficient enough though
function Calculate()
Coach.Roll.Volume = 0.1 + Driver.Velocity.Magnitude/50
if Coach.Roll.Volume >= 0.5 then Coach.Roll.Volume = 0.5
end
while true do
wait(0.1)
Calculate()
end
I like to avoid using while loops… this will do the job quite nicely.
local p = 0
local min = math.min
local roll = Coach.Roll
game:GetService'RunService'.Stepped:connect(function ()
local n = tick() % .1
if n < p then
local volume = Driver.Velocity.magnitude / 50 + .1
roll.Volume = min(0.5, volume)
end
p = n
end)
Why would you do that? If I’m not mistaken, connecting to an event will create a new thread every time the event fires whereas a while loop reuses the thread. Seems needlessly complicated and even hurts performance.