Modulescript receives table instead of object

I have a modulescript that has the functions to control the partcache and from another script I am calling a function like

print(fireball.Name)   -- prints "Fireball" correctly
FireballCacheControllerModuleScript:returnFireballToCache(fireball)

then in the modulescript

function FireballCacheControllerModuleScript.returnFireballToCache(fireBallToReturn: BasePart)
	print(fireBallToReturn) -- prints "table:0x9c1a1a7aa07ccfba"
	print("returning fireball with name: " .. fireBallToReturn.Name)  -- this is line 29
....
end

and the next line throws an error
Workspace.Alearning.FireballCacheControllerModuleScript:29: attempt to concatenate string with nil]

Why does the object I am sending turn into a table?
How does this make sense?
I have no idea where to look to solve this or what to try.
Please advise!

ModuleScripts return tables if they have been required already somewhere in the Script, and from what I have heard they also return tables if another Script required it

you are using the incorrect calling method. On your modulescript you have function module.func(args) and on the script that calls you have module:func(args). Change one of them and it should work.

You put a function inside of table, you should just return the function, not the table.

Thanks a bunch!
That solved it. Just had to change “:” to “.” in the script using the module script and now it works as I expected it to.

FireballCacheControllerModuleScript:returnFireballToCache(fireball)
changed to
FireballCacheControllerModuleScript.returnFireballToCache(fireball)

I could never have figured that out myself.

I guess @KJry_s is also trying to explain the same thing, but that is unfortunately still half chinese to me.

Alr, so what I think you have right now as the code is:

local FireballCacheControllerModuleScript = {}

FireballCacheControllerModuleScript.returnFireballToCache = function()
    -- Code thing you put here
end

return FireballCacheControllerModuleScript 

What you can do instead is:

local returnFireballToCache  = function()
    -- Code here again
end

return returnFireballToCache

(This was what I was trying to explain, sorry for talking chinese)

1 Like