For k,v not working?

I am making a sound script where it will play a sound on all players locally. This is the problem :

(server side)

	for k,v in pairs(player.GetAll()) do

its only playing it for the player with k “1” but not others. The net is sent to client which runs this :

(client side)

net.Receive("RFinalSound", function()
	net.ReadEntity():EmitSound("Snare_Sound", 100, 1000, 1)

Im not sure what is going on, please help.

I don’t get it, why are you trying to network this?

Entity:EmitSound exists on both the server and the client, so why not just do it all serverside?

for _, p in pairs( player.GetAll( ) ) do
     p:EmitSound( "Snare_Sound", 100, 1000, 1 )

PS: As far as I’m aware, you can’t network players like that. Your best bet would be to use net.Broadcast() instead of net.Send( pPlayer ) and instead of looping all of that.

Or because its client to server, use net.SendToServer()

I don’t get it. You are sending a player to the same player? For what? Also how you can often resolve problem with networking in my experience is by first putting them in a local variable and then using the variable instead.

Serverside, net.Broadcast dispatches messages to every client by default. There’s no need to use a loop through every player to do it.


That’s all you need to create the message.

Or you net message it to client, then running EmitSound on LocalPlayer(), then you don’t have to use any loops.

Or just do what kpjVideo suggested and do it all serverside. Much easier.

just do it all serverside?

local function playsnareshound
	for k,v in pairs(player.GetAll()) do
V:EmitSound("Snare_Sound", 100, 1000, 1)