Hello, here's what I've tried:
--Client, remoteEvent game.ReplicatedStorage.RemoteEvent:FireServer(function() return "This is a string" end)
--Server, remoteEvent game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(plr, func) func = func() print(func) end)
This gives the error: Cannot call nil value
But, this next script prints the string.
-- Client, BindableFunction game.ReplicatedStorage.Function:Invoke(function() return "This is a string" end)
-- Client, BindableFunction2 game.ReplicatedStorage.Function.OnInvoke = function(object) object = object() print(object) end
This is super weird, if anyone can help me, that would be great!
All data is located inside the machine's own memory. When you assign a value to a variable, what you're really doing is assigning a pointer that points to the value's very own memory address.
Functions are simply blocks of machine code instructions located in the machine's memory. When you assign a function to a variable, it assigns a pointer that points to the function's very first instruction.
When you're trying to send a function over the network, you're actually trying to send the pointer to that function. The pointer, like already mentioned, is just a memory address. The server machine does not share its memory with the client machine, thus the function does not exist on the server machine and the pointer points to nothing meaningful.
You can send other values because their bit-representation is simple. The client grabs the bit-data from the memory and sends that instead of the pointer.
Why not send the machine code then? Other value types are independent. Functions rely on many different pointers that all point to some other addresses, that again, don't exist on the server machine. The instructions may also differ a little depending on the machine.