Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Can I send tables through remote functions?

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.

1 answer

✓ Accepted answer

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

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

####Illustration 2

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

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

Thanks,

Best regards,

IdealistDeveloper

1 comment

0

Okay, now I understand it. Thanks so much for the help!

This discussion is preserved as it was. New answers, comments, and votes are closed.