Unknown error - attempt to yield across metamethod/C-call boundary

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

I’d like to make a list that shows all of the gamepasses inside of an object, wrapped in a PCall, but I keep on getting this error I know nothing about. (See screenshot)

I have the pcall return errors in warns, if any.

image

My script

function AddPurchaseValue(instance)
	if instance:IsA("IntValue") then
		local Clone = script.PurchOptTemplate:Clone()
		
		local g,b = pcall(function()
			Clone.ProductValue.Value = instance.Value
			local app = Marketplace:GetProductInfo(Clone.ProductValue.Value,Enum.InfoType.Product)
			local textcost = 'R$ '..app.PriceInRobux
			Clone.Text = textcost
			Clone.Parent = script.Parent.Container.Will.DonoBut.Dropdown.Container
			Clone.Activated:Connect(function()
				script.Parent.Parent.Parent.CurrentProductId.Value=Clone.ProductValue.Value
				script.Parent.Parent.Parent.Cost.Text = textcost
			end)
		end)
		if b then warn('ERR: '..b) Clone:Destroy() end
	end
end

use ypcall instead of pcall. ypcall allows for yielding.

1 Like

Thanks, I had no idea pcall doesn’t allow yielding.

Ypcall is deprecated, though. What can I do about that?

Which line does this error? What happens if you remove pcall from it, does it error the same thing?


Incorrect in Luau and Lua 5.2+. You’re talking about vanilla Lua 5.1

You don’t need to change from pcall to ypcall, the reason why ypcall is deprecated is because Roblox’s Lua (Luau) changed so that pcall can yield. Don’t use deprecated APIs, it’s a bad practice.

@gooey333 This is Luau, not vanilla Lua 5.1; Luau supports Lua 5.2’s pcall yielding. In fact, ypcall is deprecated because pcall can now yield. You shouldn’t encourage the use of deprecated API.

2 Likes