Attempted to call require with invalid argument(s)?

I have been following a youtube tutorial which I’m still trying to learn some of what the coding does because its decently advanced and cam across this issue: Attempted to call require with invalid argument(s):

I have a folder in Starterpack called ModuleScripts which obviously stores much ModuleScripts into:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local StarterPack = game:GetService("StarterPack")

local PunchEffectsEvent = ReplicatedStorage.RemoteEvents:WaitForChild("PunchEffectsEvent")

PunchEffectsEvent.OnClientEvent:Connect(function(...)
	local Argument = {...}
	
	local Module = require(StarterPack.ModuleScripts.PunchEffectsModule:FindFirstChild(Argument[1]))
	
	Module[Argument[2]](Argument)
end)

I believe the issue is that :FindFirstChild is in the require function itself, not after the parentheses.

Current:

local Module = require(StarterPack.ModuleScripts.PunchEffectsModule:FindFirstChild(Argument[1]))

“Fixed”:

local Module = require(StarterPack.ModuleScripts.PunchEffectsModule):FindFirstChild(Argument[1])

Also, are the dots intentional?

In the tutorial he did this:

local Argument = {...}

Also, I am getting a blue error:

Link me the tutorial. I am not sure what he did

Oki dokie. Here is the YouTube video: How to make your first Combat System R15 and R6 | Part 2 - YouTube

What about the timestamp?

It’s most likely that the module you try to find doesn’t exist there. Try changing it from this:

local Module = require(StarterPack.ModuleScripts.PunchEffectsModule:FindFirstChild(Argument[1]))

to this:

local RequirePath = StarterPack.ModuleScripts.PunchEffectsModule:FindFirstChild(Argument[1])

print(RequirePath)

local Module = require(RequirePath)

This won’t fix the problem, but it’ll see if it can find the module you’re referring to. When you try this, tell me what it prints.

Your “Fixed” code is wrong, you are finding a child when the module is required.

Yeah I’m aware. The original didn’t make sense either

I have wrote it like this:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local StarterPack = game:GetService("StarterPack")

local PunchEffectsEvent = ReplicatedStorage.RemoteEvents:WaitForChild("PunchEffectsEvent")

PunchEffectsEvent.OnClientEvent:Connect(function(...)
	local Argument = {...}
	
	local RequirePath = StarterPack.ModuleScripts.PunchEffectsModule:FindFirstChild(Argument[1])

	print(RequirePath)

	local Module = require(RequirePath)
	
	Module[Argument[2]](Argument)
end)

In the output it printed nil

The time it starts is 18:00 minutes into the video.

Sure enough, the module didn’t get found. Next, try printing out the Arguments table, I’m thinking it might not have anything.

What’s a module script is doing in a starterpack?
Move it to ReplicatedStorage then require it.

Or maybe your modulescript is in a tool that you’ve forgot to mentioned?

:FindFirstChild returns nil if a child in the parent doesnt exists.

That is extremely weird, he really does just put some dots in there. You’ve scripted the module and put it in the correct location, right?

Yes. Its very strange… If all goes wrong should I just restart the entire video?

I’d just end up learning scripting from other tutorials and making your own combat system. This entire tutorial is a bit weird and the majority of the comments are either botted or issues with the script

1 Like

the dots returns the table of the arguments, for example:

local function lol(...)
    print(...) -- it will print {"hi","world","ok","bye"}
end

lol("hi","world","ok","bye")
2 Likes

I’m surprised I didn’t know that, thanks for the insight!

@AustnBlox so then you would probably have to return something… are you giving parameters when you call the punch effects event?

Ok yes. I might as well show you the other script that is connected to this one. I think I may have confused everyone by not showing this ModuleScript:

This is the LocalScript we are talking about now where the issue is and inside the ModuleScript folder is the ModuleWScript and this is whats inside:

local TweenService = game:GetService("TweenService")
local Debris = game:GetService("Debris")

local Meshes = script.Meshes

local PunchEffectsModule = {}

function PunchEffectsModule.Effects(Argument)
	local Folder = Instance.new("Folder")
	
	Folder.Name = "PunchEffects"
	Folder.Parent = workspace
	
	Debris:AddItem(Folder, 1)
	
	coroutine.wrap(function()
		for Index = 1, 12 do
			local Sphere = Meshes.Sphere:Clone()
			
			Sphere.Size = Vector3.new(0.1, 0.1, 0.1)
			Sphere.CFrame = Argument[3].CFrame * CFrame.Angles(math.rad(math.random(-180, 180)), math.rad(math.random(-180, 180)), math.rad(math.random(-180, 180))) * CFrame.new(0, 0, -0.5)
			Sphere.Parent = Folder
			
			Debris:AddItem(Sphere, 0.25)
			
			TweenService:Create(Sphere, TweenInfo.new(0.25), {CFrame = Sphere.CFrame * CFrame.new(0, 0, -10)}):Play()
			TweenService:Create(Sphere, TweenService.new(0.125), {Size = Vector3.new(0.2, 0.2, 5)}):Play()
			
			task.delay(0.125, function()
				TweenService:Create(Sphere, TweenService.new(0.125), {Size = Vector3.new(0.1, 0.1, 0.1), Transparency = 1}):Play()
			end)
		end
	end)()
end

return PunchEffectsModule

Hoping this helps.

Can you try doing print(…) And see if that’s causing any problem?