Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

How could I store variables in modules?

Asked by 12 days ago

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

1 answer

Log in to vote
0
Answered by
orcazate 140
12 days ago

I mean it's pretty self-explanatory, You're not even returning your desired module block. You would need to insert your variables into the Module pair of brackets

Ad

Answer this question