play a sound clientside

what is the hook to play something client-side ?

ty, but why does it say “surface” ?

Because it’s meant for GUI’s but it works however you use it.

okay :slight_smile:

[editline]05:15PM[/editline]

function OverrideDeathSound ( ply, surface )
surface.PlaySound( "/music/hl2_song20_submix0.mp3" )
	return true
end
hook.Add("PlayerDeathSound", "OverrideDeathSound", OverrideDeathSound)

why does it not work?

error:

init.lua:1242: attempt to index global 'surface' (a nil value)

You do not need to use surface as an argument; surface is a global (clientside) library and if you redefine it, you will break things.

so what should i do?

function OverrideDeathSound ()
Instead of
function OverrideDeathSound ( ply, surface )

i still get same error.

The code is probably being run server-side for some reason

but does anyone know how to play a sound for the player and not for everyone?

clientside, surface.PlaySound( “/music/hl2_song20_submix0.mp3” )

Put it in cl_init.lua not init.lua