Difficult question about scripts and local scripts

Ok so. Since we can transfer functions from script/localscript to modulescript. Can we transfer from server script to local one.
Or for example script->module->localscript.
EDIT: If we can’t do it so simple what about complicated ways.

3 Likes

I am not sure what your asking but if a module is in replicated storage you can use it on both the client and the server. You can use remote functions to run functions on the server or client and get the return on the other.

Ok listen. Ik we cant do it without remote functions. But i tried do it with remote and it wont run.

The only way local scripts can communicate with the server, or vice versa, is either with remote events or functions, there is no other way.

The server and client can’t communicate through module scripts.

You can’t pass functions through remote/bindable events. The data has to be serializable.

Finnaly some dude who understand my question. But any way to do it if we cant do it through remotes.

No you cannot you will need to use modules

There wouldn’t be a way to pass the “function” itself. Some have suggested you can place it in a module script and have the client/server require, and run it when they need to. (do note that require()ing a ModuleScript is not replicated. The server and client get their own copies.)

If you need the client to have a result of a function, InvokeServer and return that result to them. Otherwise, there’s no way either side can “send” a function to the other.

Here one problem. I can’t do like script->module->localscript. Cuz function wont transfer local.

Can you explain what you are trying to do?

1 Like

So if i would do smth like
1.making function on server
2. Module.test(ourfunction)
3. In module script. - local FunctionForLocal = ourfunction
3.2. fire all clients with new function
4. Run function on client.
Would it work?

Effects optimization. Making function on server and run them on clients.

No. As stated before, module return values aren’t replicated across the client/server boundary. They each have their own copy.

Since you’re doing effect optimization, have the server send the parameters of the function to the clients, then have the clients run the function with the information given to them by the server.

Can i get any example? Cuz it sounds like remote with function.

In my opinion, the only way to pass a function through Server Scripts and Local Scripts is sending them via a String and using loadstring() on the client. That’s if you ain’t using modules.

Each function has an unique ID which idk how is this one called.

how i would make functionstring and make it with loadstring()

local Code = [[
workspace.Gravity = 100
]]

Just send the Code variable via a RemoteFunction/RemoteEvent and do this on client.

local FunctionForCode = loadstring(Code)
FunctionForCode()

EDIT: Remember this is not a good practice because it will error if you indexed something on ServerStorage/ServerScriptService which is nil on client…

image

Omg yes, I forgot you need the Custom Loadstring module. Loadstring is disabled on the client.