This script is returning a error when trying to use a function from a module, for some reason.
Module Script
local module = {}
function testfunction()
print("worked")
end
return module
Script
local vm = require(script.Parent)
while task.wait(1) do
vm.testfunction()
end


The issue here is that in your ModuleScript you are defining the function testfunction but not actually putting it inside the table that the module returns.
When you write function testfunction() without specifying a table, Lua creates it as a regular global or local function depending on the scope, but it does not become a property of your module table. Since your script is returning module and calling vm.testfunction(), Lua will look for a key named testfunction inside the module table, but it will not find it, resulting in the error you are seeing.
In short, the reason your code fails is that module is empty when returned, because you never attached the function to it. By attaching it with either of the two:
function module.testfunction()
module.testfunction = function()
...
end
The table you return will actually contain the function, and your call in the main script will work as intended.
2 Likes