invrt
|
  |
| Joined: 02 Dec 2015 |
| Total Posts: 12 |
|
|
| 17 Jun 2017 07:36 PM |
Alright, so I have trouble with Module Scripts so I decided to make a VERY easy one. --------------------------------------------
TestScript (located in Workspace):
myModule = require(game:GetService("ServerScriptService").ModuleTestScript) myModule.printThis("The Room Where It Happens")
--------------------------------------------
ModuleTestScript (located in ServerScriptService):
local module = {}
function printThing(text) print(text) end
return module
--------------------------------------------
Very simple, right? Now, somebody please tell me why I get this error and how I can fix it: Workspace.TestScript:2: attempt to call field 'printThis' (a nil value)
|
|
|
| Report Abuse |
|
|
|
| 17 Jun 2017 07:37 PM |
Hello, since you are returning the "module" table.. the function must be in the table.
local module = {}
function module.printThing(text) print(text) end
return module
|
|
|
| Report Abuse |
|
|
|
| 17 Jun 2017 07:38 PM |
| printThis doesn't exist in your module. It's printThing. |
|
|
| Report Abuse |
|
|
| |
|
invrt
|
  |
| Joined: 02 Dec 2015 |
| Total Posts: 12 |
|
|
| 17 Jun 2017 07:40 PM |
Ah, thanks! I understand the scripts better now, also thanks for the quick reply.
|
|
|
| Report Abuse |
|
|
invrt
|
  |
| Joined: 02 Dec 2015 |
| Total Posts: 12 |
|
|
| 17 Jun 2017 07:55 PM |
Okay, sorry but I have another issue. Here's the script. ----------------------------------------- ModuleScript:
local module = {}
function module.onTouch(hit) print(hit.Name) local humanoid = hit.Parent:FindFirstChild("Humanoid") local walkSpeed = humanoid.WalkSpeed local speedBoost = 20 local regularSpeed = 16 for i = regularSpeed, speedBoost + 1 do walkSpeed = i wait() end end
return module ----------------------------------------- Script:
local scriptFunctions = require(game:GetService('ServerScriptService').ModuleScript)
script.Parent.Touched:connect(scriptFunctions.onTouch()) ----------------------------------------- ServerScriptService.ModuleScript:4: attempt to index local 'hit' (a nil value)
I'm trying to make a little Speed Run function via the Module Script so that I can reuse it at ease.
|
|
|
| Report Abuse |
|
|
|
| 17 Jun 2017 07:57 PM |
| script.Parent.Touched:connect(scriptFunctions.onTouch) |
|
|
| Report Abuse |
|
|
invrt
|
  |
| Joined: 02 Dec 2015 |
| Total Posts: 12 |
|
| |
|