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:
01 | local ServerBans = { "me" } |
02 |
03 | local RemoteFunctions = { |
04 | ReturnBanned = function (player) |
05 | return ServerBans |
06 | end |
07 | } |
08 |
09 | Remotes.ClientInformation.OnServerInvoke = function (player,action,...) |
10 | if RemoteFunctions [ action ] then |
11 | RemoteFunctions [ action ] (player,...) |
12 | end |
13 | end |
And the client-side is:
1 | local 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.
Hi gioni,
1 | local function return_something() |
2 | return "something" |
3 | end |
4 |
5 | local 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. |
7 | end |
1 | local function return_something() |
2 | return "something" |
3 | end |
4 |
5 | local 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. |
7 | end |
A simple fix to your code is this:
01 | local ServerBans = { "me" } |
02 |
03 | local RemoteFunctions = { |
04 | ReturnBanned = function (player) |
05 | return ServerBans |
06 | end |
07 | } |
08 |
09 | Remotes.ClientInformation.OnServerInvoke = function (player,action,...) |
10 | if RemoteFunctions [ action ] then |
11 | return RemoteFunctions [ action ] (player,...) -- This returns whatever that function returns. |
12 | end |
13 | end |
Thanks,
Best regards,
IdealistDeveloper