I’ve been wondering this for a while but I would like to know the best way to create the most effective server-sided cooldown that creates the least amount of lag since I heared.
If Tab[Char] ~= true then
Tab[Char] = true
wait(1)
Tab[Char] = false
end
If I ever needed to make a cooldown I would use something like os.time() each time the player activated something and compare the current os.time() to the their last os.time() to get the elapsed time.
Yes, the link you provided is much better than this option. You don’t want to yield when you don’t have to. You can read this: Avoiding wait() and why to understand more about why yielding is not good. Remote events also run on their own thread which means that you can be yielding on a bunch of threads. It is just cleaner to use the one you linked.
tick() is better for this situation, because of its precision. Os.time() is only down to the second, so you wouldn’t be able to use decimals. With tick(), you can.
All of the above are great and utilising traditional debounce cases will probably net you a half decent server-sided cooldown.
You’ll want to minimise the amount of load at all times.
The thread you provided is perfectly appropriate and I’d highly recommend you fork that kind of methodology and put it into your own code with your own use cases.
The only reason why that will cause a memory leak is because your setting the value to false, instead set to nil so the reference properly gets removed:
if (not Table[Character]) then
Table[Character] = true
wait(1)
Table[Character] = nil --removing the reference thus stopping memory leaks
end