Recently I was working with a script using values and encountered a problem. I noticed that values don't change when using variables. Here is what I mean:
local value = script.TEST.Value --test being an intvalue value = value +1
I noticed this did not change the value. Value is still 0. However if I write what I think is the exact same thing:
script.TEST.Value = script.TEST.Value +1
Guess what? Value changed! It is now equal to 1.
I have looked online for a bit and not found anything regarding this, I am really confused why this is happening. Could anybody explain?
When you do value = value + 1, your not changing the Value property of Test. Your actually assigning a new Value to the variable.
local Variable = script.TEST.Value Variable = Variable + 1 -- Same as: Variable = script.Parent.Value + 1 print(script.Parent.Value) -- prints 0, through this entire script, the value has never been changed. print(Variable) -- prints 1, Variable's value has been changed on line 3.