Timers + ply = nope

Why are timers so uncooperative?
[lua]
timer.Simple( 1, function()

		player:EmitSound( "/npc/combine_soldier/vo/off2.wav", 100, 100)
	end)

[/lua]


attempt to call method 'EmitSound' (a nil value)

player is NULL.

ply is also a nil value (even if I put function(ply) instead of just function() OR call a separate function using timer.Create instead of timer.Simple)

When using timers it’s good practice to make sure that your entity still exists after the delay of the timer, the easiest way to do this is with Entity:IsValid() or IsValid(), like this:
[lua]timer.Simple( 1, function()
if not IsValid( player ) then return end – end the function if the player is no longer valid
player:EmitSound( “/npc/combine_soldier/vo/off2.wav”, 100, 100)
end)[/lua]

what is ply/player, where are you defining it (or where is the function that gives that parameter)

I tried it, here’s my full code with the function:
[lua]
function chatCommands( ply, text, public, surface )
if (string.sub(text, 1, 11) == “affirmative”)
ply:EmitSound( “/npc/combine_soldier/vo/affirmative.wav”, 100, 100)
timer.Simple( 1, function()
if not IsValid( player ) then return end
player:EmitSound( “/npc/combine_soldier/vo/off2.wav”, 100, 100)
end)
return(false)
end
end
hook.Add( “PlayerSay”, “chatCommands”, chatCommands )
[/lua]

Error:
OH WAIT there is none. The sound just doesn’t play. I’m 100% sure that’s a valid sound… no errors at all.

[lua]
function chatCommands( ply, text, public, surface )
if (string.sub(text, 1, 11) == “affirmative”)
ply:EmitSound( “/npc/combine_soldier/vo/affirmative.wav”, 100, 100)
timer.Simple( 1, function()
if not IsValid( ply ) then return end
ply:EmitSound( “/npc/combine_soldier/vo/off2.wav”, 100, 100)
end)
return false
end
end
hook.Add( “PlayerSay”, “chatCommands”, chatCommands )
[/lua]