I'm trying to get a function from a server script to a local script, is this possible? I've tried this
local myRemoteFunction = script.Parent.load -- RemoteFunction function myRemoteFunction.OnServerInvoke(plr,code) return function() print("Test") end end
But I don't think return works with functions. I've also tried putting the function in a table, this didn't work either. Thanks. (Someone asked me to put this)
local myRemoteFunction = script.Parent.load -- RemoteFunction function myRemoteFunction.OnServerInvoke(plr,code) return {["Func"] = function() print("Test") end} end
No you cannot. See this answer..
It isn't possible to send a function over the network, because functions can change local variables. That means any use of the function would somehow involve reaching into another computer's memory (which is at best dangerous, if not impossible)
Functions are sent across the network for typically several reasons
1) they're a method of a class. In that case, you can just annotate objects with which class they are, and setmetatable
on the receiving end according to the annotate class (see linked answer for example code)
2) you're asking them to invoke a particular function from some set of functions. In that case, just say which function (e.g., by the name). The receiver has to look it up in the table:
-- module RemoteFunctions return { printTest = function() print("test") end, }
-- client remote:InvokeServer("printTest")
local Fs = require(RemoteFunctionsModuleScript) -- server function remote.OnServerInvoke(player, fun) if not Fs[fun] then return "invalid function name" end return Fs[fun]() end
Have you tried loadstrings? when you want to run a local in a server script try
lp=game.Players.<UsernameHere> lp:runLocalScript[[( lp=game.Players.LocalPlayer == LocalCode Here == )]]