"Attempt to load a function from a different lua VM"

Hello, so I’m creating this block coding system for a game. However, whenever I try and run my test block data script, this error pops up:

 Attempt to load a function from a different Lua VM  -  Server - Script:14
  19:37:24.944  Stack Begin  -  Studio
  19:37:24.945  Script 'Workspace.Script', Line 14 - function runBlockData  -  Studio - Script:14
  19:37:24.945  Script 'Workspace.Script', Line 22  -  Studio - Script:22

This is my test executor module as well as the “ComposeVector3” module that I’m loading:

--!native
local runService: RunService = game:GetService("RunService")
local isServer: boolean = runService:IsServer()

if not isServer then return 0 end

local lookupTable: {[string]: {[string]: any}} = require(game.ReplicatedStorage.ExecutorData.BlockData)
local blockFuncs: {[string]: () -> any} = game.ServerStorage.Messages.GetBlockFuncs:Invoke()
local scriptData: {[string]: any} = {Variables = {}}

local function runBlockData(data: {[number]: {[string]: string | number}})
	for id: number, blockData: {[string]: string | number} in ipairs(data) do
		local status: {[string]: boolean | any} = blockFuncs[blockData.Id](data.Parameters, scriptData)
		assert(data.Success, data.Value)
		
		if #blockData.ConnectedBlocks > 0 then runBlockData(blockData.ConnectedBlocks) end
	end
end

local start: number = os.clock()
runBlockData({{Id = "ComposeVector3", Parameters = {X = 10, Y = 20, Z = 30, Vector3Variable = "AwesomeSauce"}, ConnectedBlocks = {{Id = "Print", Parameters = {Variable=Vector3.new(10,20,30)}, ConnectedBlocks = {}}}}})
scriptData["Benchmark"] = os.clock()-start
return scriptData

ComposeVector3 module:

--!native
return function(data: {[string]: any}, scriptData: {[string]: any})
	local result: Vector3 = Vector3.new(data.X, data.Y, data.Z)
	scriptData.Variables[data.Vector3Variable] = {Value = result, Type = typeof(result)} 
end

I think the issue has to do with scriptData.Variables, and if so, how would I go about changing the variable data without causing this error to appear?

You cannot use functions that you got returned from or passed to a bindable or remote event.

2 Likes

That clarifies it up, let me try it out. By the way, is there any way to give more context in script errors? I really don’t want to counter one of these again.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.