07-08-2011, 06:26 PM
Disabling sleep() in events would solve a whole lot of issues and confusing things about scripting (having to use gamecheduleTask() when creating a model from an event handler, for example), but I don't want to do it anyone needs it.
If you just need to disable a tool for an amount of time after a player uses it, using os.time() works just as well. This is the way Buildism and most other games handle this type of thing internally--using sleep() adds an extra thread that does nothing.
[lua]lastClickTime = os.time()
function mouseDown()
if os.time() - lastClickTime < 3 then return end --3 seconds
[...]
lastClickTime = os.time()
end[/lua]
If you just need to disable a tool for an amount of time after a player uses it, using os.time() works just as well. This is the way Buildism and most other games handle this type of thing internally--using sleep() adds an extra thread that does nothing.
[lua]lastClickTime = os.time()
function mouseDown()
if os.time() - lastClickTime < 3 then return end --3 seconds
[...]
lastClickTime = os.time()
end[/lua]