How to recognize when standard methods/functions are yielding?

Hello
I noticed that when I change a property of an object in a script, this immediately triggers the callbacks listening for changes in this object and my script is interrupted.
How can I recognize which calls inside the script can trigger such behavior (or which standard functions can yield) ? I know about the usual suspects - wait(), WaitForChild, etc., but I did not expect that setting of a single property will also pause the execution of my script.
Generally speaking, how can I аssess whether my code will be executed in a linear fashion?

Thank you

I’m not sure what properties you would be changing to cause the script to yield. Which properties are you changing? It would be easiest to help with samples of code, perhaps put a comment on the line where the yield is happening and then post the excerpt here

Here is a small example. This script is under a Part in the workspace.
The message “Transparency changed” is printed before the message “back in main script”.
How can I recognize in which cases 2 lines in my script will be executed in a sequence without another code interrupting them?

local debounce = false

workspace.PizzaBig.Plate:GetPropertyChangedSignal("Transparency"):Connect(function()
	print("Transparency changed :) ")
end)

script.Parent.Touched:Connect(function(hit)
	if debounce then return end
	local humanoid = hit.Parent:FindFirstChild("Humanoid")
	if humanoid then			
		workspace.PizzaBig.Plate.Transparency = 0.1
		print("back in main script")
				
		debounce = true
		wait(3)
		debounce = false
	end
end)

I’m having trouble understanding the question
You are changing the transparency before you are printing “back in main script” which fires GetPropertyChangedSignal

There is no yield, the property changed signal just happens to get run before the "back in main script" print runs. If you put a wait(1) inside the GetPropertyChangedSignal function, you’ll see there’s no yield between changing the property and moving to the next part of the script.

Yes, I do
My question is how to recognize cases where my code will not be executed in linear fashion line by line?
I know now that setting a property may cause such effect.
But how to recognize the other cases? (beyond the obvious - wait(), WaitForChild, task.spawn, etc)

Setting an Instance’s property cannot cause your code to yield. luau_callTM specifically mentions that yielding is NOT supported. A simple demonstration of this can be performed in the following way:

local obj = newproxy(true)
getmetatable(obj).__newindex = coroutine.yield
obj.a = 3 --> Error: attempt to yield across metamethod/C-call boundary

The only functions that I can think of in the extended Roblox library which yield are wait and task.wait. If you are unsure if a function in Roblox’s reflection API yields, you can search for it at Anaminus’ reference docs. Functions which yield will explicitly be described as such:

3 Likes