Result returning "attempt to call a table value" from pcall()

Hi. I’m using a remote function to send a request to the server to get product info. I checked all the info and it should work but I feel like I’m missing something simple.
Client Side:


Server Side:

Watch Variables:

You can see success is false and return is resulting in the “attempt to call a table value” even though cat is a numeric value.

pcall will attempt to invoke the first argument (expects a callable object) and pass any other arguments to the function. In this case you’re already invoking the RemoteFunction and using the value returned from the invocation as the argument for pcall to attempt to call which is erroneous.

You likely instead meant to pass a lambda that returns the result of the invocation.

local success, result = pcall(function ()
    -- This evaluates to a table and returns it to the lambda which is
    -- used as the result of the pcall.
    return getInfo:InvokeServer(cat)
end)

cat is a numeric value so that shows up correctly in your variable watcher and the server will, as told to, return the result of GetProductInfo. The reason why it’s telling you that you’re attempting to call a table variable is the above problem: InvokeServer returns a table which is then passed to pcall. The table in question doesn’t have a __call metamethod on it so it can’t be called.

1 Like

Thanks. I knew it was something simple.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.