Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why can't RemoteFunctions return functions?

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

✓ Accepted answer

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).

This discussion is preserved as it was. New answers, comments, and votes are closed.