Attempt to index nil

So, I’m making a gun system, first person shooting, I’m on a part right now where there was an error prior. Anyway, there’s two separate scripts. My Module Script which has the settings, and the local script which has the framework and what not.

An error that I’m getting is “attempt to index nil with ‘fireRate’”. As far as I am aware, attempt to index nil essentially means it can’t be found. This was working perfectly fine earlier though without error, and I haven’t changed the variable for the module.

I’ve checked inside the module script and everything is spelled correctly. If anyone has solutions, please respond.

while wait() do
	if isShooting then
		print("FIRING")
		mouse.Button1Up:Connect(function()
			isShooting = false
		end)
		wait(framework.module.fireRate)
	end
end
local Settings = {
	
	name = "M4A1";
	
	canAim = true;
	aimSmoothness = .25;
	
	fireAnim = "rbxassetid://18267927393";
	fireSound = game.ReplicatedStorage.Sounds.M4A1.Fire;
	
	canSemi = true;
	canFullAuto = true;
	fireMode = "FullAuto";
	
	fireRate = .25;
}

return Settings
2 Likes

Change wait(framework.module.fireRate) to wait(framework.Settings.fireRate) and see if that works

4 Likes

“Attempt to index nil” is an error that occurs when you’re trying to point to the property of something that doesn’t exist. So, you’re trying to find the ‘fireRate’ property of nil, which means your script doesn’t know what framework.module is.

Is framework your variable for the ModuleScript after being required? If so, you should follow @LordOfSapphire’s advice and change framework.module to framework.Settings.

2 Likes

Do note, the module script is in Replicated Storage, under Modules, named M4A1

image

1 Like

Show where the framework variable is defined

1 Like

1 Like

change the line where framework.module is defined to “local framework = require(moduleFolder:FindFirstChild(Item))”

Oh, you don’t need to define Settings. When you call require(), it returns the table of the module. So just using framework.fireRate should work.

I did that prior, it didn’t work.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.