What are yielding functions?

What does it mean when a function yields? On this page GlobalDataStore | Roblox Creator Documentation yields.

1 Like

It will pause and hold up the code until it finishes running. wait is a yielding function. So is WaitForChild. GetAsync will hold up the code until it finishes running, whenever the data finishes loading.

So GetAsync() is like this

repeat
	dataStore:GetAsync()
until dataloaded == true
1 Like

In the way that the code under it won’t run until the data is loaded. Behind the scenes of course it looks vastly different.

Hello JayO_X!

A yielding function is one that stops the code from executing until it has finished returning.

An example would be as follows.

local testtick = tick()
GlobalDataStore:GetAsync()
print(tick() - testtick) --depending on how long the function takes to finish yielding, this can vary from a couple milliseconds to seconds

You could compare it to the same as waiting.

local testtick = tick()
wait(5)
print(tick() - testtick) --these are similar because a yielding function **waits** until it is ready to return what it needs to
1 Like