Task Scheduler

The Task Scheduler is the internal scheduling system of the Roblox engine that is responsible for coordinating tasks, including processes of other internal systems such as input, networking, rendering, and physics. The scheduler also handles script execution and is responsible for API objects such as services and events to function properly. Tasks are coordinated by the scheduler according to the stepping of a frame.
The scheduler has its own API which can be accessed through the task library and .
The built-in profiling tool MicroProfiler records information about Task Scheduler processes in real-time, which is accessed by pressing .
== Frames ==
The frame is a unit of game logic used by the scheduler to perform tasks each step. In game development, every task on a frame must performed efficiently for a faster frame rate (also measured in frames per second, or FPS).
A frame is stepped when all tasks of the CPU and the GPU are finished. However, the frame rate has a built-in maximum of 60 FPS, so a frame will not step faster than this rate.
Although the engine running in Roblox Studio or the Roblox Player can run at a maximum of 60 FPS, Roblox servers run at maximum of 30 FPS. The networking is separate from frames, running at a maximum of 20 hertz.
== API ==
=== task ===
The task library has functions allowing functions and threads to be scheduled with the Task Scheduler: 
;task.spawn(functionOrThread: | , ...: ): 
:Calls/resumes a function/coroutine immediately through the scheduler.
;task.defer(functionOrThread: | , ...: ): 
:Calls/resumes a function/coroutine on the next resumption cycle.
;task.delay(duration: , functionOrThread: | , ...: ): 
:Schedules a function/coroutine to be called/resumed on the next Heartbeat after the given duration (in seconds) has passed, without throttling.
;task.wait(duration: ): 
:Yields the current thread until the next Heartbeat in which the given duration (in seconds) has passed, without throttling.
;task.cancel(thread: ): 
:Cancels a thread, preventing it from being resumed.
The task library also has functions relating to parallel Luau, which work only if run by a script in an :
;task.desynchronize(): 
:Switches the thread to parallel state (assigns it to a different worker).
;task.synchronize(): 
:Switches the thread to serial state (assigns it to the main thread).
=== RunService ===
The houses events that fire every frame. The events are different from each other that they fire at different priorities. RenderStepped is fired first, then Stepped, and then Heartbeat. The RunService allows the client to bind functions to a render step with a specific priority using RunService:BindToRenderStep(), which are called before the RenderStepped event.
== Third-party software ==
* Roblox FPS Unlocker removes the limit of 60 frames per second.
== External links ==
*Task Scheduler on the Roblox Creator Documentation
*task on the Roblox Creator Documentation
Category:Scripting
Category:Experience features