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:
local ServerBans = {"me"} local RemoteFunctions = { ReturnBanned = function(player) return ServerBans end } Remotes.ClientInformation.OnServerInvoke = function(player,action,...) if RemoteFunctions[action] then RemoteFunctions[action](player,...) end end
And the client-side is:
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,
local function return_something() return "something" end local function get_invoked() return_something() -- You see how "something" is returned but just lays there. You need to return that value which is returned. end
local function return_something() return "something" end local function get_invoked() 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. end
A simple fix to your code is this:
local ServerBans = {"me"} local RemoteFunctions = { ReturnBanned = function(player) return ServerBans end } Remotes.ClientInformation.OnServerInvoke = function(player,action,...) if RemoteFunctions[action] then return RemoteFunctions[action](player,...) -- This returns whatever that function returns. end end
Thanks,
Best regards,
IdealistDeveloper