So I made this script for my battlefield that makes explosions happen every few seconds, and a sound plays when an explosion goes off. I set the MaxDistance to 250 so you can only hear it if you're close to it, but it doesn't seem like it changes anything and I can hear it at the same volume from the same distance. The sound in Workspace has a MaxDistance of 250, and I also put it as part of the script to make sure it's that number but I can still hear it anywhere. Here's the script below.
Sound = game.Workspace.BlowUpSound function BlowUp() local Explosion1 = Instance.new("Explosion",workspace) Explosion1.Name = "Bomb1" Explosion1.Position = Vector3.new(-56, 43.1, 9.8) Explosion1.BlastRadius = 2 Explosion1.BlastRadius = 13.8 Explosion1.DestroyJointRadiusPercent = .5 Explosion1.ExplosionType = "NoCraters" end repeat wait(10) BlowUp() Sound.MaxDistance = 250 Sound:Play() until script.Disabled == true
In case others run into Sound issues...
'Sound' needs to be parented to a 'basepart' or 'attachment' or it's considered global and the volume won't be effected by 'MaxDistance'.
Addtionally, while the playback of sounds will replicate, other properties such as the playback speed, pitch, volume, etc. will not replicate. This behavior can be avoided by creating all sounds locally on the client, as instancing sounds will not replicate to the server. 'Sound.TimePosition', 'Sound.TimeLength' and 'Sound.Playing' will all replicate to the server.
For sound to decrease in volume, you can set 'Sound.EmitterSize'. The lower the number value, the smaller the "area" to which once a player reaches, the sound will then fade.
'Sound.RollOffMode' is the property that determines the volume fade for 3D sound, increasing the fade as the distance increases using 2 things, the sound's Parent and the listener (deafult is the Camera Position).
sound.RollOffMode = Enum.RollOffMode.Linear --or see below
The four options include:
Linear - Volume fades between 'Sound.EmitterSize' and 'Sound.MaxDistance' with a linear relationship.
LinearSquare: Volume fades between 'Sound.EmitterSize' and 'Sound.MaxDistance' with a linear squared relationship.
Inverse: Volume fades from 'Sound.EmitterSize' in an inverse manner.
LinearSquare: Volume fades between 'Sound.EmitterSize' and 'Sound.MaxDistance' with a linear squared relationship.
Note, 'Sound.MaxDistance' will not effect fading under the inverse model but will cause the sound to cut off completely once this distance is reached. This can be particularly abrupt when using low values for max distance.