'SendLua' (a nil value)

I’ve created another SWEP, and I want it to play a random sound out of the list I have provided. Here is my problem though, the first sound it makes, I get this error

'SendLua' (a nil value)

In more detail

[ERROR] addons/wheatley/lua/weapons/wheatley.lua:65: attempt to call method 'SendLua' (a nil value)
  1. unknown - addons/wheatley/lua/weapons/wheatley.lua:65

Timer Failed! [ScarySoundsEmit][@addons/wheatley/lua/weapons/wheatley.lua (line 69)]

But after the first error, the following sounds are flawless of errors, and do not print anything wrong in the console.
Howcome it is only the first, and would you be able to check the below and tell me what line to change so the first error is never printed?

local tab = {

local function ScarySounds()
    local sound, plytab = table.Random(tab), player.GetAll()
    for k = 1, #plytab do
        plytab[k]:SendLua("surface.PlaySound(\"".. sound .."\")")

timer.Create("ScarySoundsEmit", 32, 0, ScarySounds)

Yea, yea. I will include all the info you want, just ask:v:

Also, could someone help me make it so that wheatley only has idle talk when I have him in my inventory? Because even if he is not equipped, he still talks,
Just a simple command line should do : )

If you only have one file, it acts the same as just having one shared file. You’re trying to call SendLua on the client, which doesn’t exist.

local function ScarySounds()
   local snd = table.Random(tab)
   for id, ply in pairs( player.GetAll() ) do
      ply:SendLua( "surface.PlaySound( '".. snd .."')" )

[editline]6th December 2013[/editline]

But might want to do it the PROPER way:

function SWEP:Deploy()
    timer.Create( "test", 30, 0, function() if ( IsValid( self ) ) then self:EmitSound( table.Random(tab) ) end end )

function SWEP:Holster()
    timer.Destroy( "test" )

don’t forget
if CLIENT then return end


function SWEP:Deploy()
    if CLIENT then return end
    timer.Create( "test" .. self:EntIndex(), 30, 0, function() if ( IsValid( self ) ) then self:EmitSound( table.Random(tab) ) end end )

function SWEP:Holster()
    timer.Destroy( "test" .. self:EntIndex() )

Hey, would you be able to explain to me what the 30 and 0 mean up there? I believe 30 is the time between each phrase, and 0 is the volume, but when I tune up the 0, my sounds are still quiet.

30 is the delay of the timer, 0 is amount of times to repeat, 0 means infinite. You should look up arguments of Entity:EmitSound on the wiki.

Thank you, one last thing. The sounds with the error causing script were loud and proud, but with this non error script you gave me (which seems to be working), the sounds have become quiet and almost impossible to hear. Any ideas?

They are played from the entity, not everywhere. With the code you were using, it would play the sounds for every player on your server no matter where they are. You should look into additional arguments for Entity:EmitSound on wiki as I stated before, or try self.Owner:EmitSound