Values won't update

I have this variable that is equal to a intvalue but when i print this variable it would print the original value of the intvalue and it would not update with the intvalue. Any solution for this?

Thank you in advance.

Example
Intvalue = 1
Variable = Intvalue
printf(Variable)
output = 1
Intvalue = 2
printf(Variable)
output = 1

Put ``` at the start and end of your code to make it look professional.

2 Likes

You need to set your variable again the second time. When you set a variable equal to another variable it doesn’t create a reference, it just assigns the value of the first variable to the second. So in your example when you call that variable again, it hasn’t changed since you originally set it to 1.

6 Likes

This should work (@ChiefWildin was correct in his answer!) :

local NewInt = Instance.new("IntValue")
NewInt.Name = "Int"
NewInt.Value = 1
NewInt.Parent = script.Parent

local Int = NewInt.Value
print(Int)

wait(2)

Int = 2

print("Value Updated!")

print(Int)

And here’s what Output looks like:

image

1 Like