Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Unknown RemoteFunction error?

Error: attempt to yield across metamethod/C-call boundary

Code on client:

local RequestSuccess, Response = pcall(function()
    return MiddleMan:InvokeServer('CheckPurchased',itemKey)
end)

Code on server (simplified):

function MiddleMan.OnServerInvoke (client,mode,...)
	local args = {...}
	if mode=='CheckPurshased' then
		local purchased = PurchasesStorage:GetAsync(tostring(client.userId) .. '_' .. tostring(args[1]))
		return (purchased==1)
	end
end

NOTES:

  • MiddleMan is a RemoteFunction in ReplicatedStorage;

  • itemKey is a string;

  • PurchasesStorage is a GlobalDataStore;

  • Data saved on PurchasesStorage is always saved as:

    • Key: userId_itemKey;
    • Value: 1

Why is this happening? How to fix it?

Any help is highly appreciated.

2 comments

0

GetAsync yields the thread, something you can't do in a C thread.

0

Solution. You just have to put it in code because I'm lazy.

1 answer

You can't use any YieldFunctions in C callbacks, particularly if they're expected to return. Both InvokeServer and GetAsync are YieldFunctions, meaning they can not be used.

Your solution in this case is possibly to get it asynchronously. Using a RemoteEvent, send a request to the server, and then wait for the response. This should solve the C boundary error because it's no longer a C callback, as it is handled by an event connection.

6 comments

0

I tried ypcall - error'd the same.

0

Well, that's your issue under any circumstances.

0

I tried without the pcall, didn't work either. It's because of the :GetAsync

0

Well, there's also that GetAsync is a YieldFunction...

0

ypcall is the same as pcall now.

0

Well now I know that, I've updated the answer to have a proper solution.

This discussion is preserved as it was. New answers, comments, and votes are closed.