Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Unknown RemoteFunction error?

Asked by
RafDev 109
8 years ago

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.

0
GetAsync yields the thread, something you can't do in a C thread. LightningRoMan 100 — 8y
0
Solution. You just have to put it in code because I'm lazy. User#6546 35 — 8y

1 answer

Log in to vote
1
Answered by 8 years ago

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.

0
I tried ypcall - error'd the same. RafDev 109 — 8y
0
Well, that's your issue under any circumstances. User#6546 35 — 8y
0
I tried without the pcall, didn't work either. It's because of the :GetAsync RafDev 109 — 8y
0
Well, there's also that GetAsync is a YieldFunction... User#6546 35 — 8y
View all comments (2 more)
0
ypcall is the same as pcall now. LightningRoMan 100 — 8y
0
Well now I know that, I've updated the answer to have a proper solution. User#6546 35 — 8y
Ad

Answer this question