delay timer in function usage

hey
so i got this code


if SERVER then
	AddCSLuaFile("autorun/voicecons.lua")
end

USay = {}

USay.WordList = {
["21"] = "chatsound/21.wav";
["jelly"] = "chatsound/jelly.wav";
["dad"] = "chatsound/dad.wav";
["hello"] = "chatsound/hello.wav";
["james"] = "chatsound/james.wav";
["tie"] = "chatsound/tie.wav";
}

function USay.ChatFunction( ply, text )
   if ply:IsValid() then
      for k,v in pairs(USay.WordList) do
         if string.find( text, k ) then
ply:EmitSound(USay.WordList[k])
         end
      end
   end
end
hook.Add("PlayerSay", "USay.ChatFunction_Hook", USay.ChatFunction)

resource.AddSingleFile("sound/chatsound/21.wav")
resource.AddSingleFile("sound/chatsound/dad.wav")
resource.AddSingleFile("sound/chatsound/hello.wav")
resource.AddSingleFile("sound/chatsound/james.wav")
resource.AddSingleFile("sound/chatsound/tie.wav")

this code meant to play X sound when you type X in the chat
so the thing is i tried to run a timer for 45 secs when the ChatFunction is called to prevent spam but for some reason i couldnt make it work. can some body help me to do it?

you can create a timer then in the sound function you can check if the timer exists, if it does then do nothing, otherwise - continue

Or if you want an example:



function USay.ChatFunction( ply, text )
   if ply:IsValid() and !timer.Exists( ply ) then -- if the timer doesn't exist (which happens when it runs out of time) then
      timer.Create( ply, 45, 1, function() end ) -- create the timer. Note I used 'ply' for the identifier because it's unique, but maybe this won't work. If it doesn't, try something like ply:SteamID64()
      for k,v in pairs(USay.WordList) do
         if string.find( text, k ) then
ply:EmitSound(USay.WordList[k])
         end
      end
   end
end


i tried to use it but its wont work for some reason so i got this one


function USay.ChatFunction( ply, text )
   if ply:IsValid()then
	for k,v in pairs(USay.WordList) do
         if string.find( text, k ) and (timer.Exists(ply:EntIndex().."_Update"))then
	print("TIMERRR!!!!")
	  else
	local delay = 45
	local times = 1
	timer.Create(ply:EntIndex().."_Update", delay, times, function()
	ply:EmitSound(USay.WordList[k])
         end)
      end
   end
end
end

however its working but the timer is set wrong for somereason
lets say then i type hello in the chat the sound hello.wav suppose to play but instead the timer delays the sound for 45 secs and after 45 secs it plays it, i need it to play the sound instantly and delay it for 45 secs



function USay.ChatFunction( ply, text )
   if ( timer.Exists( "supertimer" ) then return end
   if ply:IsValid() then
      for k,v in pairs(USay.WordList) do
         if string.find( text, k ) then
ply:EmitSound(USay.WordList[k])
         timer.Create("supertimer", 45, 1, function() print("timer started") end )
         end
      end
   end


does this work, untested*

hell yeah it is
thanks, you just forgot to close the ( in line two and add one more end