So I replaced all my wait() with task.wait() because I heard that its better for the game. Now my game is noticeably WAY more laggy so my question is. Is there some occasions where wait() is better to use than task.wait() ??
3 Likes
task.wait() is more efficient and accurate than wait(). The most likely reason you’re experiencing more lag is that your current scripts do too much work too quickly, since task.wait() only waits for 1 frame which is much faster than wait().
7 Likes
-- Using task.wait()
print("Starting task.wait() example...")
local startTime = os.clock()
task.wait(1) -- Pauses the script for 1 second
local endTime = os.clock()
print("task.wait() example finished. Elapsed time:", endTime - startTime)
-- Using wait()
print("Starting wait() example...")
startTime = os.clock()
wait(1) -- Pauses the script for 1 second
endTime = os.clock()
print("wait() example finished. Elapsed time:", endTime - startTime)
4 Likes
Starting task.wait() example...
task.wait() example finished. Elapsed time: 1.000023 (approximately)
Starting wait() example...
wait() example finished. Elapsed time: 1.035421 (approximately)
5 Likes
Doesn’t both wait()
and task.wait()
capture how long it took to run?
local t1 = wait(1);
local t2 = task.wait(1);
print(`wait() example finished. Elapsed time: {t1}`)
print(`task.wait() example finished. Elapsed time: {t2}`)
2 Likes
You are good go run script working done
2 Likes