Help with module scripts

I’m looking to try and use module scripts and using require to call scripts throws an “invalid argument” error. All scripts are currently in StarterGui. I’ve tried using different arguments for require (findfirstchild) and messing with parent-child relations between scripts.

Main:

local GRI = require(script.Parent:FindFirstChild("GRI")) -- Rotates 
local UIHandler = require(script.Parent:WaitForChild("UIHandler")) -- Displays things (WIP)

GRI:

 local GRI = {}
-- Existing code and function

return GRI 

UI Handler:

local UIHandler = {}


return UIHandler
1 Like

to debug this i would recommend you put print throughout the module script.

also i would use WaitForChild(‘objectname’) for the GRI Thing.

also if a module errors, it goes to the script that required the module.

2 Likes

I have had prints at the various stages to debug within the modules. FindFirstChild was used to replace WaitForChild because the latter was broken too (cf. “I’ve tried using different arguments for require (findfirstchild)” ). I included it in here, one for each require, in case it was syntax error on my end. The error is going to main, so my scripts do continue to work, but the issue is that whenever I try to require in other scripts it breaks and this is a pretty fundamental concept I can’t get under control.

1 Like

if the modules are being used in multiple scripts i recommend putting them in replicated storage so its easier to access them and might solve the errors.

do make sure the requires are also updated with this change

1 Like

The modules specified are not being used in multiple scripts, but I will try to put them in replicated storage. How would I update the requires to reflect this change?

making it say game.ReplicatedStorage.SpecifiedModule instead of script.Parent.SpecifiedModule

2 Likes

Switching GRI and UIHandler to ReplicatedStorage, keeping Main in StarterGUI, still threw the error. I tried, in main: "local GRI = require(game.ReplicatedStorage:WaitForChild(“GRI))” "local GRI = require(game.ReplicatedStorage:FindFirstChild(“GRI))” and “local GRI = require(game.ReplicatedStorage.GRI)” all of which still threw “Attempted to call require with invalid argument(s). - Server - Main:1”

hold on a second. i see a problem. the waitforchild and findfirstchilds were missing the quotation on the right side(for the game.replicatedstorage reply)

That was my fault retyped it wrong, the script it has the quotes inside the parentheses, I threw myself off by retyping it here with the extra quotes to distinguish the various fixes I tried

local GRI = require(game.ReplicatedStorage:WaitForChild("GRI")) -- Rotates 
print ("GRI-tings")
local UIHandler = require(game.ReplicatedStorage:WaitForChild("UIHandler")) -- Displays things (WIP)
print ("Handy Module")

Ok i’m a bit confused at this point cause based off of the scripts you shown. it should work. unless replacing .ReplicatedStorage with :GetService(‘ReplicatedStorage’) works. besides that, i dont know

1 Like

Ill definitely give that a try. Asked my programming coworkers as well but I’m still waiting on a response

1 Like

So, realized I’m silly goofy and never actually put the script in a ModuleScript, its all working now lol

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.