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

Why can't I return a function from a RemoteFunction?

Asked by
gskw 1046 Moderation Voter
9 years ago

In a script inside a RemoteFunction, which is inside workspace, I have the following:

function script.Parent.OnServerInvoke(_)
    return function()
        print("hi");
    end;
end;

Then, inside a LocalScript, which is inside the StarterGui, I have the following:

local function loadstring(src)
    return workspace.RemoteFunction:InvokeServer(src);
end;
loadstring()();

This causes the following error:

12:35:23.263 - Players.Player1.PlayerGui.LocalScript:4: attempt to call a nil value
12:35:23.263 - Stack Begin
12:35:23.263 - Script 'Players.Player1.PlayerGui.LocalScript', Line 4
12:35:23.263 - Stack End

What's wrong with this application?

0
Probably to prevent that loadstring hack where you can just return a function from the server. But there might be an actual reason. jakedies 315 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago

As I'm not quite positive why this is happening I will give two posibilities.

1: The return function is actually returning the return value of the function due to some strange evaluation priority. 2(more likely). I'm fairly sure that a function when defined takes a snapshot of the variable environment which is certainly a security concern if you're moving this function to the client. Why ROBLOX made the return value nil rather then just erroring when a function is returned I don't know.

Ad

Answer this question