I was wondering if there was anything faster than task.wait(0)
It would really help to speed up some things in my game.
Thanks,
RGF
I was wondering if there was anything faster than task.wait(0)
It would really help to speed up some things in my game.
Thanks,
RGF
Canât you use just wait()? That waits super fast from my knowledge.
Tbh the slow code is not likely to be from a wait and is more likely bad coding or smthing.
Before the wait, repeat a count for 256 as a test first
Isnât renderService.Heartbeat faster?
Either runservice heartbeat or renderstepped
(note: if your game is laggy then you shouldnât use thisbas it will be even slower than wait())
What do you need this for? Different methods are better for different purposes.
thereâs really nothing unless you use task.wait(0) like what you did in the post
Hi,
Instead of a faster wait, you should instead group some tasks together.
Letâs say we have 10000 parts we want loaded, but we cannot do it all at once without lag.
And if we use task.wait() for each part we load in, then itâs gonna take a while.
Instead we group them into parts of 250. Meaning that instead of 10000 task.wait()'s, we only use 40.
This is true, but be aware that too many operations in one frame can be a problem if youâre not handling it correctly.
But to answer your question directly, it kind of depends. task.wait()
is the same as RenderStepped.Heartbeat:Wait()
. Heartbeat
runs every physics frame (which is 60 fps) after physics have been calculated. RunService
has multiple other options for example when you want to jump in. Such as before a physics frame.
Hereâs a list from RunService:
Technically the fastest delay would be RenderStepped as this is the FPS youâre probably thinking of. Itâs only client-side, but it happens prior to every render frame. This will be faster as it matches with FPS even if the user is using an FPS unlocker (going above 60 fps). But itâs important to note that that this should only be used for render-specific things and can cause issues if not handled correctly. For the majority of cases, you should just use task.wait()
.
Yea, Iâm sure everyone knows that the more stones you put onto a scale, the more it weights.
Note that my quotation was not to reply to you directly, Iâm sure you were aware of that already. I was simply referencing it to explain a potential danger for those who are unaware. Thereâs a wide range of skill levels here on the developer forum (and obviously Roblox in general), so I prefer to cover things more in-depth where possible and realistic. Anything can be a learning moment.
Yea that certainly makes sure that everything is accounted for.
local function FastWait(Time)
local Clock = os.clock()
repeat until os.clock() - Clock > Time
return os.clock() - Clock
end
local Time = FastWait(0.0001)
print(Time) --0.00010019994806498289
This is not a âwaitâ function. This doesnât yield- it executes 0.0001 milliseconds of work. This wonât give other threads the ability to run like task.wait() can.
It is a âwaitâ function in that it waits for some length of time before continuing (busy waiting). I know it doesnât yield but there was no mention of that being a requirement in the original post.
I was wondering if there was anything faster than task.wait(0)
is there a way to make it yield?
If you want to keep it simple, you can just use RunService. There are several different events you can yield for, such as Heartbeat, RenderStepped, Stepped, and some others.
Iâve already mentioned it in my previous post.
The most you can do, that I know of, to make that os.clock example âyieldâ is by removing the math operation and just doing this, using about the same code:
function FastWait(yield)
local clock = os.clock()+yield
repeat until os.clock() >= clock
return os.clock()-(clock-yield) -- This line can be removed if you don't care about a return value.
end
print(FastWait(0.0001)) -- 0.00010000000020227162 (Time may vary, but barely.)
If you remove the parenthesis on the return part, os.clock()-clock-yield
will always return 0.0001
(or whatever your input was), but negative for some reason.
u can also use RunService.PreRender or task.defer(function()
The fastest wait function is the negligible time between execution of each line of code, while true do end is the supreme method of scripting
task.wait() will wait for a frame, itâs tried to the framerate, so 1/60 of a second if the fps isnât unlocked and isnât lagging. So, if you want to go faster than that, youâll have to run (the function, or whatever you want to run) more than once per frame