Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why won't my script detect this ModuleScript function?

I'm making something quite confusing: a client script that calls a RemoteEvent that in turn calls a ModuleScript function. The client script and the RemoteEvent work fine, but once I introduce the line calling the ModuleScript function, it all breaks.

This is essentially what the ModuleScript is (some irrelevant parts have been omitted):

local Convert={}

function Convert.CellToPosition(player,cell)
    --This function does a bunch of math and returns a position
end

function Convert.PositionToCell(player,position)
    --This function does a bunch of math and returns a cell
end

return Convert

This is how I call it from another script:

--Assume player and cell are not nil
Convert.CellToPosition(player,cell)

This is the error that I get: CellToPosition is not a valid member of ModuleScript

Any attempts of debugging the script have failed. Whenever I try to print something anywhere in the script, it doesn't appear.

1 answer

✓ Accepted answer

You are attempting to access a child of a ModuleScript, not accessing the table it contains. In order to get the returned value from a ModuleScript, you have to require it.

local Convert = require(ModuleScript)

1 comment

0

Duh, of course! smacks forehead Thanks so much!

This discussion is preserved as it was. New answers, comments, and votes are closed.