Play sound on player death

So I recently started learning about hooks, and I am trying to make it so when you die, it plays a sound.


resource.AddFile("sound/deathinversion.mp3")

local InvDeathSound = ("deathinversion.mp3")

local function PlayerDeath()
	surface.PlaySound( "deathinversion.mp3" )
end

hook.Add( "PlayerDeath", "SoundOnPlayerDeath", PlayerDeath)


So what my problem is, I am getting an error saying something along of the lines of “surface is a nil value”

I tried using BroadcastLua, but, it played every time anyone died.

I’m not a good coder in anyway (as you can see), so if anyone could help me or point me in the right direction it would be appreciated.

try specifying the location

like “sound/whatever/deathinversion.mp3”

I would do something like this.
[lua]
if SERVER then
AddCSLuaFile()
util.AddNetworkString(“DeathSound”)
hook.Add(“DoPlayerDeath”, “RandomDeathSound”, function(ply, attacker, dmginfo)
if !IsValid(ply) then return end
net.Start(“DeathSound”)
net.Send(ply)
end)

hook.Add("Initialize", "OverrideGMValues", function()
	function GAMEMODE:PlayerDeathSound() return true end
end)

else
local Sounds = {“garrysmod/ui_click.wav”, “ambient/water/drip3.wav”}
net.Receive(“DeathSound”, function(len, ply)
surface.PlaySound(table.Random(Sounds))
end)
end
[/lua]