I've been trying to learn how to use modules, and, I attempted to use a table to store my variables. It keeps saying 'Attempted to index nil with "meditating"', and I don't know why it's happening, or where I went wrong in holding the variables. Code:
local module = {}
local var = {
rs = game:GetService("ReplicatedStorage"),
run = game:GetService("RunService"),
cas = game:GetService("ContextActionService"),
meditating = false,
enrg = script.Parent.Parent:WaitForChild("Power")
}
module.MedButton = function(action, inputState, var)
if action == "meditating" then
if inputState == Enum.UserInputState.Begin then
var.meditating = true
print(var.meditating)
elseif inputState == Enum.UserInputState.End then
var.meditating = false
print(var.meditating)
end
end
end
module.medstepfunc = function(var)
if var.meditating == true then
var.enrg.Value = math.clamp(var.enrg.Value + 10*deltaTime, var.enrg.MinValue, var.enrg.MaxValue)
print(var.enrg.Value)
end
end
return module
Any explanations/help is appreciated
