This is about using a timer in an if structure. What I want to do is when a player executes a function, they cannot use that function for x amount of time. For example, /function outputs I am a function. then if the player tries to use the function again, /function outputs You cannot use me for X seconds. Any help would be appreciated.
[lua]
CanUse = true
function Use()
if(CanUse) then
CanUse = false
print(“Used.”)
timer.Simple(30, function() CanUse = true end)
else
print(“You can’t use this function.”)
end
end
[/lua]
Thanks alot!
You can also write it like this:
[lua]
local LastUsed = 0
local Delay = 5
function Use()
if (LastUsed + Delay) < CurTime() then
LastUsed = CurTime()
print("You used this! ;O")
else
print(“You can not use this! >:(”)
end
end
[/lua]