Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

Why can't RemoteFunctions return functions?

Asked by 9 years ago

For some reason, this only works on play solo

Server sided loadstring IS enabled

Server script:

local rf = Instance.new("RemoteFunction")
rf .Parent = game.Workspace
rf.Name  = "loadstring"
function rf.OnServerInvoke()
    local toreturn = loadstring([[
        print('Hello')
    ]])
    return toreturn
end

Local script:

func = game.Workspace.loadstring:InvokeServer()
func()

1 answer

Log in to vote
4
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

Functions are far too complicated to send across the network.

The most obvious problem would be with closures, which can change/read variables:

local myBlah = 5

function changer(new)
    myBlah = new
end

changer(3)
print(5);

remoteFunction:InvokeServer( changer )

-- They can now call changer ... and some how... my RAM will be updated
-- with whatever they want?
-- (This is impossible)

You shouldn't use loadstring, and you don't need to send functions across usually. Instead, send the information that that is needed. If you use a ModuleScript, you can indicate which function you're talking about. Or, you could point out a RemoteFunction that needs to be called (if it really does need to be handled by the client).

Ad

Answer this question