Learning about module scripts for the first time. I following along what it tells me to do in the official roblox guide for module scripts (https://developer.roblox.com/en-us/api-reference/class/ModuleScript). This is what my code looks like:
SCRIPT 1:
local functions = {} function functions.test() print("test") end return functions
SCRIPT 2:
wait(3) local test = require(script.Parent.test) test.test()
I get: Attempted to call require with invalid argument(s).
Not really sure why this is happening, as I did EXACTLY what it told me to do in the Roblox guide.
A dude four years ago had a similar issue: https://scriptinghelpers.org/questions/24931/attempted-to-call-require-with-invalid-arguments-solved. Unfortunately, once he figured it out, he didn't bother to explain what the solution was. He just said "solved in chat", and "error was in the title". This doesn't help me at all.
I'm sure it's just some dumb mistake I'm making here, I just don't know what. Any assistance is welcomed.
Oh, yeah, I think I see the issue.
local functions = {} functions.test = function() print("test") end return functions
try this code inside of the module script.
The error might be your script IS loading after it requires. Try this maybe?
--This is a module script, place in ServerScriptService --I'll call this script "ModuleScript" local functions = {} functions.test = function() print("test") end return functions
Server script
--This is a server script, place in ServerScriptService local ModuleScript = require(game:GetService("ServerScriptService"):WaitForChild("ModuleScript") ModuleScript.test()
Sorry if this didn't work!
After watching AlvinBlox's video (https://www.youtube.com/watch?v=tT9gyw9127Y), I found out that this error was being caused because I was attempting to put the module instead of a LocalScript, rather than a ModuleScript. I know, noob mistake. Laugh it up, lol. I was not aware there was an actual separate script type called a ModuleScript. I thought you just put the module in a LocalScript or something.
Now the question I have is this:
Since I know now that there's a separate script type for ModuleScripts, are ModuleScripts able to see things created by both LocalScripts and ServerScripts? And more specifically, are ModuleScripts able to run UserInputService?