How to pass a variable by reference?

I have an variable, that I pass into a function located on a module script, and at the end of that function, the variable gets set to nil. However, back on my localscript, the variable still holds a value.

Any suggestions?
Thanks!

If the function within the module is something that runs really quickly, couldn’t you just return the value and set it as the new one?
Example:

Module:

local module = {}

function module.updateValue(num)
    --do stuff with the number
    --...
    return num
end

return module

Script:

local module = require(pathToModule)

local value = 0
while task.wait() do
    value = module.updateValue(value)
end

My code looks a little more like this:

localscript:

myModule.DestroyAndNil(myPart)

Module:

function module.DestroyAndNil(input)
    if input then
        input:Destroy()
        input = nil
    end
end

should I do this instead?

localscript:

myPart = myModule.DestroyAndNil(myPart)

Module:

function module.DestroyAndNil(input)
    if input then
        input:Destroy()
        input = nil
        return nil
    end
end

yeah, that will also set the myPart variable in the LocalScript to nil, cleaning up the memory :+1: