Need help passing a function across Lua VMs and being able to call it without the error "Attempt to load a function from a different Lua VM"

Let’s say that I have a BindableFunction located in ReplicatedStorage, and a LocalScript inside the StarterPlayerScripts folder which has the following code:

game.ReplicatedStorage.Function.OnInvoke = function()
	return game:GetService("PublishService").CreateAssetOrAssetVersionAndPollAssetWithTelemetryAsyncWithAddParam
end

The code above makes a Lua function, which will get the CreateAssetOrAssetVersionAndPollAssetWithTelemetryAsyncWithAddParam function of PublishService, then return it to the invoker of the BindableFunction.

Now, when I try to invoke the BindableFunction in a different Lua VM, such as the CommandBar, I am able to print the memory address of the function:

But I can’t call it:

Is there any way to pass a function between different Lua VMs and still be able to call it in a different VM? Perhaps a service that I missed, that allows communication between different VMs and I am able to pass a function via that?

Thank you!

That’s the magic of Bindables.

You’re trying to access two different memory stacks. Which you can’t do in Luau.

1 Like