Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

MaxDistance Won't Affect Sounds?

Asked by 5 years ago

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


0
Forgot to add I'm new to scripting and this is probably a noob-ish question lol NoahsRebels 99 — 5y
1
If the sound isn’t parented to a basepart or attachment, the sound is considered global and MaxDist won’t effect it, as far as volume is concerned. ABK2017 406 — 5y
0
Ah I see. I'll try to fix that now. NoahsRebels 99 — 5y
0
It worked! Thanks for the help. NoahsRebels 99 — 5y
0
Np, Glad it worked. ABK2017 406 — 5y

1 answer

Log in to vote
1
Answered by
ABK2017 406 Moderation Voter
5 years ago
Edited 5 years ago

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.

Ad

Answer this question