Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why won't my script detect this ModuleScript function?

Asked by 7 years ago

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

Log in to vote
1
Answered by 7 years ago

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)
0
Duh, of course! *smacks forehead* Thanks so much! ChipioIndustries 454 — 7y
Ad

Answer this question