ply.LastTauntTime in if (SERVER) then

I’m trying to create a taunt delay for a menu.

the server side code:


if ( SERVER )	then 
	local TAUNT_DELAY = 3		//Taunt Delay Variable
	
	ply.LastTauntTime = 0

	util.AddNetworkString("send_taunt")
	net.Receive("sent_taunt",function(_, ply)
		local taunt = net.ReadString()
		if ply.LastTauntTime + TAUNT_DELAY <= CurTime() then
			ply.LastTauntTime = CurTime()
			ply.EmitSound(taunt,150)
		end 
	end )
end


Now the thing is I want to make by default ply.LastTimeTime be 0 and also affect each player individually.

Any tips on how to do it properly?



net.Receive("sent_taunt",function(_, ply)
		local taunt = net.ReadString()
ply.LastTauntTime = ply.LastTauntTime or 0 // If the variable does not exist by default ( which it does not on server start ), make it 0
		if ply.LastTauntTime + TAUNT_DELAY <= CurTime() then
			ply.LastTauntTime = CurTime()
			ply.EmitSound(taunt,150)
		end 
	end )

[editline]2nd March 2016[/editline]

This will also cover the case where something might set the variable to nil for whatever reason.

[editline]2nd March 2016[/editline]

(Like a script that would use the same variable)

It works, but after 5± seconds you can play other taunts… while the first one playing…

Then TAUNT_DELAY is not set to the correct time

Thing is there’s taunts that are quite long…
So any tips on how to solve?

I would make a table containing the taunt delays as values and make the taunt’s name (Or any identification form) the key, like so:
[lua]local taunt_length = {
[“taunts/props/1.wav”] = 1, //Boom Headshot!
[“taunts/props/2.wav”] = 0, //Doh!
[“taunts/props/3.wav”] = 3, //Go away, or I shall taunt you.
//And so on and so on
}[/lua]
And then use taunt_length[taunt] instead of TAUNT_DELAY

I thought this was included by default in your menu O.o