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
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.
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
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?
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