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 8 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):

01local Convert={}
02 
03function Convert.CellToPosition(player,cell)
04    --This function does a bunch of math and returns a position
05end
06 
07function Convert.PositionToCell(player,position)
08    --This function does a bunch of math and returns a cell
09end
10 
11return Convert

This is how I call it from another script:

1--Assume player and cell are not nil
2Convert.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 8 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.

1local Convert = require(ModuleScript)
0
Duh, of course! *smacks forehead* Thanks so much! ChipioIndustries 454 — 8y
Ad

Answer this question