Encoding functions to string and back?

I was wondering if it was possible to encode functions to string and back with Roblox Lua.

This is mainly for organizational purposes so I can store client and server functions in one module script in serverstorage and encode and send the client the functions they need, and no more.

JSONEncode does not work:

HttpService = game:GetService("HttpService")
mytab = {hi = function() print"Hello World!" end }
print(HttpService:JSONEncode(mytab))

>>{"hi":null}
1 Like

This is not possible nor recommended. If you’re desiring to share code across Server and it’s Clients, just use a ModuleScript placed in ReplicatedStorage. It’ll accomplish the same thing

9 Likes

uGH

But I hate the idea of storing server functions and client funtions in seperate module scripts for each ‘spell’ I am making.

1 Like

Well regardless, you don’t want to expose the server side part of it, assuming you’re doing sanity checks on server, people could see that code and exploit it

It’ll just be uglier than neccessary, but I guess I’ll have to

1 Like

I mentioned something about why the limitations are here (it’s about metatables but the reason is because of functions): Metatables aren’t being sent with the tables they are assigned to?

1 Like

When I say use a ModuleScript in ReplicatedStorage, I’m thinking more of a “foundation” or “core” module for both Server and Client for maintaining a similar base for easier management of code. Definitely do not put functions which are dedicated to the Server in this Module. If any, put the core module along with any utilities/libraries which need to be shared, nothing else.