Confused With ModuleScript Errors (unknow global & attempt to index nil)

Hello, thank you for taking the time to try and help me,

I have a module script that holds the settings for a door in my experience,
I get an error in the module script and in the game even though “debounce” and “setting” exists inside the module.

Below is the error and code inside the module script

error

error2

local Door = script.Parent.Door
local setting = {
	door = Door, 
	doorPart = Door.Door, 
	hinge = Door.Hinge, 
	prompt = Door.Door.ClickDetector, 
	activationDistance = 5, 
	timeToOpen = 3, 
	openAngle = -80, 
	isOpen = false, 
	debounce = false,
	getOpen = function()
		return setting.isOpen
	end, 
	setOpen = function(value)
		setting.isOpen = value
	end, 
	getDebounce = function()
		return setting.debounce
	end, 
	setDebounce = function(value)
		setting.debounce = value
	end
}
return setting

I might be not seeing it even though it could be right infront of me so thank you.

1 Like

You’re gonna have to call the functions outside of the table

local Door = script.Parent.Door

local setting = {
	door = Door, 
	doorPart = Door.Door, 
	hinge = Door.Hinge, 
	prompt = Door.Door.ClickDetector, 
	activationDistance = 5, 
	timeToOpen = 3, 
	openAngle = -80, 
	isOpen = false, 
	debounce = false,
	
}


getOpen = function()
	return setting.isOpen
end
setOpen = function(value)
	setting.isOpen = value
end
getDebounce = function()
	return setting.debounce
end
setDebounce = function(value)
	setting.debounce = value
end

return setting

Alright thank you, but how would I then call those functions from within my script? I get an error
image

Would I return each of the functions?

I tried this it didn’t work*

30

Here (from a server script or client):

Module:

local Door = script.Parent.Door
local module = {}

local Settings = {
	door = Door, 
	doorPart = Door.Door, 
	hinge = Door.Hinge, 
	prompt = Door.Door.ClickDetector, 
	activationDistance = 5, 
	timeToOpen = 3, 
	openAngle = -80, 
	isOpen = false, 
	debounce = false,

}


function module.getOpen()
	return Settings.isOpen
end

function module.setOpen(value)
	Settings.isOpen = value
end

function module.getDebounce()
	return Settings.debounce
end

function module.setDebounce(value)
	Settings.debounce = value
end

return module , Settings

Script (local or server):

local ModuleLocation = script.Parent

local Module = require(ModuleLocation)

Module.getOpen()

Module.setOpen()

Module.getDebounce()

Module.setDebounce()

Here are good resources on how to use modules:

1 Like

Oh alright thank you!

303030333