Error: attempt to yield across metamethod/C-call boundary
Code on client:
1 | local RequestSuccess, Response = pcall ( function () |
2 | return MiddleMan:InvokeServer( 'CheckPurchased' ,itemKey) |
3 | end ) |
Code on server (simplified):
1 | function MiddleMan.OnServerInvoke (client,mode,...) |
2 | local args = { ... } |
3 | if mode = = 'CheckPurshased' then |
4 | local purchased = PurchasesStorage:GetAsync( tostring (client.userId) .. '_' .. tostring (args [ 1 ] )) |
5 | return (purchased = = 1 ) |
6 | end |
7 | 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.