How to update source variables used as argument inside functions?

Is it possible to pass arguments by reference (being not a table)?

local function Update(var1, var2)
    var1 += 1
    var2 *= 2
end

Update(workspace.Part.IntValue.Value, workspace.Part2.IntValue.Value)

In the example above, how could I change the original values?
AFAIK, I currently need this:

local function Update(var1, var2)
    return var1 + 1, var2 * 2
end

workspace.Part.IntValue.Value, workspace.Part2.IntValue.Value =
     Update(workspace.Part.IntValue.Value, workspace.Part2.IntValue.Value)

You could pass a reference to the object itself instead, then modify its value within the Update() method.

local function Update(var1, var2)
    var1.Value += 1
    var2.Value *= 2
end

Update(workspace.Part.IntValue, workspace.Part2.IntValue)
1 Like