Troubles with EmitSound not being heard by other players


I recently wrote a short script that emits a sound when players goes into and out of chat. Problem is, while you can hear it for yourself, you can’t hear other players emitting the sound.

The code is running clientside, it’s as simple as:

local sound = "some/sound/location.wav"

Anyone know where I might be going wrong?

use surface.PlaySound instead?

The problem is you’re doing it clientside. Clientside code is only executed on that client(player)'s machine.

To make your system work (Audible “going into chat” sound) the client needs to tell the server about it so the server can warn every other player. This means you need to do some basic networking.

You’ll want to use the net library or console commands to tell the server which server is going into chat and then use EmitSound on that player serverside.

Will this allow others to hear it too?

Ahh I was hoping EmitSound dealt with that for me. I guess I could let the server know everytime someone goes into chat and get it to play on everyone’s client. I thought there might be a playsound command that just did it for me.


Turns out sound.Play may work, it is a shared function that emits a sound at a given vector position. However trying to use it in the “FinishChat” hook gives me the error: bad key to string index. Anyone had experience with that?


I was using sound.Play(sound,LocalPlayer():GetPos()). Stupid me used the name “sound” as the variable name. Changing it to something else got rid of the errors.