Sound being heard globally despite setting MaxDistance

#1

I am making a function which creates a bullet hole when you shoot a gun. It fires a remote with all the data to create the bullet hole part such as the position and material. The server then fires all clients besides the player who shot the gun, which triggers a function to create the part.

A sound is put into the part with the MaxDistance set to 25 and EmitterSize to 10. However, the sound can be slightly heard by everyone in the game.

Sound.Parent = Part
Sound.Volume = 0.2
Sound.MaxDistance = 25
Sound.EmitterSize = 10
Sound.PlayOnRemove = true
Sound:Destroy()

I have also had this issue with my custom footstep noises script which clones a sound from ReplicatedStorage that already has the MaxDistance set as 25.

I have not found any solutions anywhere nor people with the same problem.

3 Likes

#3

Do you have SoundService.RespectFilteringEnabled as true? With this property set to true, sound playback will not replicate. Without it, sound playback will replicate from client scripts.

2 Likes

#4

Yes, I have it set as true.

2 Likes

#5
  • RespectFilteringEnabled
  • Sounds operated by the client
  • Sound playback apparently being replicated…?

There’s only two things I can think of: an oversight or a bug. If it’s an oversight, I haven’t the slightest clue as to what’s going on.


On an off-topic note, I just want to note something about your code and how you’re setting your properties after Parent. Typically when creating a new Instance, you should set its properties first before its Parent. Something to do with performance. A PSA was released regarding this practice in 2016:

1 Like

#6

Based on the property description on the wiki, MaxDistance will only work if the sound is parented to a Part or Attachment.

In your example code, you destroy the sound object which sets its parent to nil. This means MaxDistance will no longer work.

Instead you could try destroying the sound after it has finished playing. For example:

--Create sound object
Sound.Parent = Part
Sound.Volume = 0.2
Sound.MaxDistance = 25
Sound.EmitterSize = 10

--Start playing the sound
Sound:Play()

--Wait for sound to finish playing
Sound.Ended:wait()

--Destroy sound object
Sound:Destroy()
3 Likes

#7

i can’t believe i didn’t see that lol

Yeah, don’t rely on PlayOnRemove. Destroy your sound after the playback is finished.

1 Like

#8

I have done this instead and the problem is fixed. Thank you!

Sound:Play()
Sound.Ended:wait()
Sound:Destroy()
3 Likes