Which sound command to use?

I want to make it so anytime a player uses voice chat there is a sound (like a radio keying up) that plays. I don’t really care if it is heard by all players or just the local player (it’s a very, very small game mode).

init.lua


util.AddNetworkString("radiokeyup")

net.Receive("radiokeyup", function()
BroadcastLua(surface.PlaySound("Radio_Keyup.mp3"))
print ("radio check confirmed")

end)

client


function GM:PlayerStartVoice( ply )
	net.Start("radiokeyup")
		net.SendToServer()
		
		end

what is best sound command to play server side…i keep getting NIL errors in console…I am trying to understand the process but don’t quite grasp the relationships of server assets vs client…

Why you want to play a sound serverside? if you mean with “serverside” to all players, then

surface.PlaySound
is fine, you just have to run it in the client hook, aka, replace “net.Start(‘radiokeyup’”) and stuff with the surface.playsound, but make sure you also force the sound to download, with resource.addFile().

Not sound “command”, its a function…

also OP, make your code nicer please >-<

If you want all players to hear it its probably best to use ply:EmitSound instead of Broadcasting surface.PlaySound

If you only want the local player who pressed the key to hear it then its not even worth sending anything to the server in this case you can do again just LocalPlayer():EmitSound(…) inside PlayerStartVoice

I think you can also just do ply:EmitSound(…) inside PlayerStartVoice where all clients that call the hook would play for the specific player (no networking required)

I think OP probably wants the sound to be “2D” and not “3D”

BroadcastLua takes a string, not direct code. So this won’t work:
[lua]BroadcastLua(surface.PlaySound(“Radio_Keyup.mp3”))[/lua]
But this will:
[lua]BroadcastLua(“surface.PlaySound(‘Radio_Keyup.mp3’)”)[/lua]