Attempted to call require with invalid argument(s)

Im not entirely sure whats going wrong here i just keep getting the error
Attempted to call require with invalid argument(s).
heres the module script

local Talents = {
	["B"] = {
	["Head"] = math.round((DmgV.Value * (gLevel.Value/10))*1.5),
	["Torso"] = math.round((DmgV.Value * (gLevel.Value/10)),
	["None"] = math.round((DmgV.Value * (gLevel.Value/10))*0.7)},
	
	["C"]  = {["None"] = math.round((DmgV.Value * (gLevel.Value/10))*math.random(0.00, 2.10))},
	
	["D"] =  {
	["Head"] = math.round((DmgV.Value * (gLevel.Value/10))*1.5),
	["Torso"] = math.round((DmgV.Value * (gLevel.Value/10))+ ((DmgV.Value *(gLevel.Value/10))/0.30)),
	["None"] = math.round((DmgV.Value * (gLevel.Value/10))*0.7)}
}


return Talents

and heres the require

local M = require(game.ReplicatedStorage.Talents)

Not sure whats going on here but id like some sort of fix to this :heart:

1 Like

I guess your ["Torso"] value has a missing closing parenthesis, causing the error?

ive fixxed some of the weird parenthesis, and it still erros

local Talents = {
	["B"] = {
	["Head"] = math.round((DmgV.Value * (gLevel.Value/10))*1.5),
	["Torso"] = math.round((DmgV.Value * (gLevel.Value/10))),
	["None"] = math.round((DmgV.Value * (gLevel.Value/10)*0.7))},
	
	["C"]  = {["None"] = math.round((DmgV.Value * (gLevel.Value/10))*math.random(0.00, 2.10))},
	
	["D"] =  {
	["Head"] = math.round((DmgV.Value * (gLevel.Value/10))*1.5),
	["Torso"] = math.round((DmgV.Value * (gLevel.Value/10))+ ((DmgV.Value *(gLevel.Value/10))/0.30)),
	["None"] = math.round((DmgV.Value * (gLevel.Value/10))*0.7)}
}


return Talents

That error means you’re calling the require() function with an argument that isn’t a ModuleScript, e.g. passing a server Script or LocalScript as a parameter. So this has nothing to do with the Talents module’s code, but rather the script requiring Talents.

If you can confirm that game.ReplicatedStorage.Talents points to exactly one instance that is a ModuleScript, I have no idea what could be wrong unless you misread the error’s source or forgot to commit a script.

Heres the error i get


and the require is at the top of the script
also i dont know if it matters but im using it as

character.Humanoid:TakeDamage(M["B"])

OmgV.Value and gLevel.Value not defined in the module script?

Try doing a

print(game.ReplicatedStorage.Talents.ClassName)

before the require to see what that says.

A not too uncommon mistake is naming a folder or something the same thing which might accidentally cause the require to try getting that instead.

2 Likes

There was a folder with the same name forgot i was testing some morestuff,
but now i got a new problem

  16:51:24.941  ReplicatedStorage.Talents:3: attempt to index nil with 'Value'  -  Server - Talents:3
  16:51:24.941  Stack Begin  -  Studio
  16:51:24.941  Script 'ReplicatedStorage.Talents', Line 3  -  Studio - Talents:3
  16:51:24.941  Stack End  -  Studio

  16:51:24.941  Requested module experienced an error while loading  -  Server - Script:20
  16:51:24.941  Stack Begin  -  Studio
  16:51:24.941  Script 'Workspace.Ak47.Script', Line 20  -  Studio - Script:20
  16:51:24.941  Stack End  -  Studio

i thought code wouldn’t run in the module script?
(Edit, i have the values unique in each tool)

When you run require it goes through all of the code as though you just put the entire script in a function and called it (though it can’t access the variables of the script that required it directly). I don’t know where/if you are defining DmgV or gLevel in your module script but one or both are nil.

1 Like

ive defined them both before i run the require

local tool = script.Parent
local FEvent = tool.fe
local REvent = tool.re
local FastC = require(tool.FastCastRedux)
local PC = require(tool.PartCache)
local cA = FastC.new()
local HttpService = game:GetService("HttpService")
local BFolder = workspace.BFolder
local BTemplate = BFolder:FindFirstChildWhichIsA("Part")
local shotTime = tick()
local fireRate = tool.FireRate.Value
local timeLimit = 2/3
local minS = 0.5
local maxS = 2
local EXP = tool.CurrentExp
local rEXP = tool.ReqExp
local gLevel = tool.GunLevel
local DmgV = tool.Damage
local M = require(game.ReplicatedStorage.Talents)

You’ve defined them in the script that you are calling require in. Module scripts have their own scope though. Just treat a module script as it’s own script because it kind of is. You can just access returned data in a module script from another script. Not the other way around though.

You can however make a function in that module script that you could use to pass in data, but then you can’t really use that data until the function is called.

i just made a quick fix with inputing the module script in the tool and then defining the values, althought this isnt what i really wanted as if i wanted to add more “Talents” i would need to go through every tool’s module script

(edit)
Never mind something else broke now

  17:47:24.544  TestService: Exception thrown in your RayHit event handler: Unable to cast Dictionary to float  -  Studio
  17:47:24.544  TestService: checkpoint Workspace.Ak47.Script:100 function onRayHit
Workspace.Ak47(50%>*2).FastCastRedux.Signal:64

Also on a unrelated note, is it better for each tool to have its own fastcast & partcache module or should i have each tool only use one module in replicated storage?

If it’s possible to put them in replicated storage and have everything reference that one modulescript that is better than having many copies.