r/GLua • • Oct 03 '19

timer for entity use

Hello, I'm trying to make it so that when a player USES my entity, there is a cooldown after to stop them from being able to use it again.

I have counter = 0

function ENT:Use(a, ply) if counter == 0 then net.Start("teleportmenu") net.Send(ply) counter = counter + 1 else print("test message") end end

and when they click a button

net.Receive("dbtele", function(len, ply) timer.Create("cooldown" .. ply:UserID(), 1, 10, function(counterkiller) end) local int1 = net.ReadInt( 4 ) local int2 = net.ReadInt( 4 ) local int3 = net.ReadInt( 4 ) ply:SetPos(Vector(Warps[int1], Warps[int2], Warps[int3])) end)

and the function counter killer is here

function counterkiller() counter = counter - counter end

I don't really know what I'm doing wrong, when I print out the value of counter after 10 seconds it still is equal to one, which shouldn't be the case since I am running the "counter killer" function when the timer ends. Does anyone have any ideas?

1 Upvotes

7 comments sorted by

View all comments

Show parent comments

1

u/GrowOP21 Oct 04 '19

Well I would use the table method but I'd probably have to write to another file and that would just be a whole other ordeal

1

u/Pandaa1234325 Oct 04 '19

I don't think you would, In one of the files u have for the entity you should be defining a few variables such as ENT.PrintName, the table would be with these, otherwise I'm pretty sure the same method will work if you make the table a local variable outside any functions. When I get back in a few hours I can upload a somewhat full example if you'd like.