ModuleScript not being indexed

Im trying to create a tool that has a ModuleScript with a boolean and when equipped, it changes the boolean from True to False, but for some reason i keep getting the error attempt to index nil with 'ModuleScript'.

--LocalScript
local Modu = require(script.Parent.Folder:WaitForChild("ModuleScript"))
local tool = script.Parent

local function ModScript()
	if Modu.Bool == true then
                Modu.Bool = false
		print("Yeah")
	else
		print("Yeah, no")
	end
end

tool.Equipped:Connect(ModScript)
--ModuleScript
local module = {}

module.Bool = true

return module
1 Like

I don’t want to use a function in the ModuleScript, but i mostly want to use it as a value holder since ModuleScripts can be used to share values with scripts.
I mostly just want to find a way to share and change a value using a ModuleScript instead of a BoolValue.

1 Like

Can you post an image of how your scripts are setup? I tested your code on my end, and everything works fine. And yes, you can use modules to hold values, so I removed my reply. I cant get it to error at all.

1 Like

You said script.Parent.Folder instead of script.Parent.Modules on line 1 (local script).

1 Like

Modules is not a valid member of tool is what i get after changing it. the ModuleScript is directly in the Modules Folder. Tried to see if moving local tool = script.Parent above the require did something different, same error.

try this:

local tool = script.Parent
local Modu = require(tool:WaitForChild("Modules").ModuleScript)

Stopped giving the error after changing it. Wasnt getting Bool until i changed it to:

module = {
    Bool = true
}

Thanks for the help!

1 Like