Need help clarify when does script runs in task scheduler

Hello, I’m trying to understand the inner working of how things works in order for Roblox’s code logic, as I’ve ran into almost unexplainable inconsistencies in the past. (Which I kindof know now)

Based on Task Scheduler (roblox.com)

It is said that “A frame is a unit of game logic where work is done”.
I can see the ordering of various things that works in scheduler priority.

But there is something missing…?

Where would something like “Begin running scripts until it yield or complete” aka. Invocation Point is in the priority list?

1 Like

What do you mean by this?

Do you mean something like task.wait(), multiple script instances, or loops?

Otherwise you can use the microprofiler to help analyze what happens frame by frame:

If you really do need to control, usually people use a custom task scheduler like in the promise libary for promise.sleep.

Like clone troopers fast wait or CustomWait.

I meant like… If you enable/parent/clone a script while the system is running (or even when the server first start), when will the content of this script start to run in a frame/tick based on scheduler’s priority list?

It will run at the same time the initial script is running. Known as cooperative multithreading. Falls into coroutine teritory. Doesn’t seem to go anywhere in the task scheduler frame by frame territory although it’s very difficult to see as it only happens at one frame.

image

debug.profilebegin("Script 2 Hello")

print("Script 2 Hello!")
local scriptTest = game.ServerStorage.Script:Clone()
scriptTest.Parent = game.ServerScriptService

debug.profileend()
debug.profilebegin("Script 3 Hello")

print("Script 3 Hello!")

debug.profileend()

If you put it in a loop like task.wait() it goes in heartbeat frame, and the cloned script will also run at the same time within the same frame in “parallel” cooperative multithreading.

while true do
	debug.profilebegin("Script 2 Hello")

	print("Script 2 Hello!")
	local scriptTest = game.ServerStorage.Script:Clone()
	scriptTest.Parent = game.ServerScriptService

	debug.profileend()
	task.wait()
end

ohhhhhhhhh, I see, but I’m still not 100% sure if it does actually separate from scheduler though.

Since I found something while digging through the forum.

This beta page [Beta] Deferred Lua Event Handling - Updates / Announcements - DevForum | Roblox said there are invocation points? Does this relate?

Yep

So the heartbeat example is an invocation profile.

Also it is noted TSKMk2 represents the roblox task scheduler.

TSMk2 is Roblox’s Task Scheduler name.

Also going to link the post, pretty interesting.

I think I understand how it runs now, thank you.

1 Like