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:
userId_itemKey
;1
Why is this happening? How to fix it?
Any help is highly appreciated.
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.