FilteringEnabled breaks a lot of my local code. Instead of rewriting all of my scripts (many of which exceed 500 lines,) I'm looking to make a workaround that passes certain functions to the server.
In principle, the local script passes the function and its environment table through a RemoteEvent. The server then receives the function and executes it. The server code looks like this:
script.RemoteEvent.OnServerEvent:Connect(function(client, func, env)
--func is a function passed by the client
--env is getfenv(func) according to the client script
setfenv(func, env)
func()
end)
However, when I test this code, an error is thrown whenever I try to use an environment variable such as print. The data in the environment table seems to be lost in transfer, leaving env as an empty table. Further research indicated that tables with mixed indices cannot be passed via RemoteEvent or RemoteFunction. Encoding the table with HttpService.JSONEncode failed for the same reason (even though it seems to me that environment tables are only indexed with Strings.)
I've tested this on both Play (with character) and a real server.
Is there any way that I can pass a function's environment table from client to server? If not, is there a more effective workaround to my problem?

2 comments
This isn't a great idea as it allows the client to execute any function they please which could be a SIGNIFICANT security flaw. Rewriting your code is probably the better option here, as any solution would need to use some pretty dirty hacks and again, compromise game security.
As a note, metatables don't get passed.