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

Can I send tables through remote functions?

Asked by 4 years ago
Edited 4 years ago

I'm attempting to return a table, which is held on the server, to the client through a remote function. The server-side looks something like:

01local ServerBans = {"me"}
02 
03local RemoteFunctions = {
04    ReturnBanned = function(player)
05        return ServerBans
06    end
07}
08 
09Remotes.ClientInformation.OnServerInvoke = function(player,action,...)
10    if RemoteFunctions[action] then
11        RemoteFunctions[action](player,...)
12    end
13end

And the client-side is:

1local BannedUsers = Remotes.ClientInformation:InvokeServer("ReturnBanned")

The issue is that BannedUsers is returning as nil, and I'm not sure why. Is it even possible to send a table through a remote function, or am I just missing something? Any help would be appreciated, thanks.

Note: When I print ServerBans inside the remote functions invocation, it prints a table ID. When I print BannedUsers on the client side, it prints nil.

1 answer

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

Hi gioni,

The problem you're having is a simple one to solve. You're just not returning what the first function is returning. It's like calling a function and having a value just lay there. What you're doing is similar to this:

Illustration 1

1local function return_something()
2    return "something"
3end
4 
5local function get_invoked()
6    return_something() -- You see how "something" is returned but just lays there. You need to return that value which is returned.
7end

Illustration 2

1local function return_something()
2    return "something"
3end
4 
5local function get_invoked()
6    return return_something() -- This returns the function call which returns "something" If you return the function then that means you're returning whatever that function returns.
7end

A simple fix to your code is this:

01local ServerBans = {"me"}
02 
03local RemoteFunctions = {
04    ReturnBanned = function(player)
05        return ServerBans
06    end
07}
08 
09Remotes.ClientInformation.OnServerInvoke = function(player,action,...)
10    if RemoteFunctions[action] then
11        return RemoteFunctions[action](player,...) -- This returns whatever that function returns.
12    end
13end

Hope I was able to help and have a wonderful day/night.

Thanks,

Best regards,

IdealistDeveloper

0
Okay, now I understand it. Thanks so much for the help! Gey4Jesus69 2705 — 4y
Ad

Answer this question