What do you want to achieve? Keep it simple and clear!
create a function that subtracts variables
What is the issue? Include screenshots / videos if possible!
the variable does not change
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
local var = 100 -- create variable
print(var) -- print variable
subtract = function(var) -- create function subtract
var = var - 1
end
subtract(var) -- call function subtract
print(var) -- print new var
when you reference var inside the function, it’s changing the var sent as an argument. To properly achieve what you’re doing you could do:
local var = 100 -- create variable
print(var) -- print variable
subtract = function(var) -- create function subtract
return var - 1
end
var = subtract(var) -- call function subtract
print(var) -- print new var
or simply:
local var = 100
print(var) --100
var -= 1
print(var) --99