Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

[SOLVED] Attempted to call require with invalid argument(s). ?

Asked by 4 years ago
Edited 4 years ago

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.

0
are you sure that the module you're requiring is valid? Mroczusek 111 — 4y

3 answers

Log in to vote
0
Answered by
Mroczusek 111
4 years ago

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.

0
Thanks for answering. Unfortunately, this did not make a difference. TheEthanMaverick 7 — 4y
0
That's odd, it worked for me. Mroczusek 111 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

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!

0
Hi, thanks for answering. I actually thought it might be the same thing, that's why I put the wait(3) at the beginning of the second script. I thought the require script might be running before the module script loaded. However, I actually found what the problem was. I'm currently making an answer post for it. Thanks for your effort though. TheEthanMaverick 7 — 4y
0
I'm interested to know what the real issue is though. Also if you solved your own problem you should put [SOLVED] in your title :) nekosiwifi 398 — 4y
Log in to vote
0
Answered by 4 years ago

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?

0
To answer your question, it depends. https://developer.roblox.com/en-us/api-reference/class/ModuleScript If the ModuleScript is required in the Client (LocalScript) it will run in the client, meaning you can get the LocalPlayer. If it's required on the server, the ModuleScript runs in the server. Hope that answers your question. You can run UIS if it's required from the client. nekosiwifi 398 — 4y
0
Ah, thank you kind sir. I would upvote your comment, but I don't have enough reputation, lol. TheEthanMaverick 7 — 4y

Answer this question