The problem here is the fact that you wrongly assume that the data variable is a reference to the property of the Numb.
To solve this problem, you would have the variables hold the IntValue/NumberValue object itself, and make a direct access to the Value property.
#Reference vs Value
It is important that you know the difference between a reference and a value.
##Reference
In Lua, for example, tables are passed by reference.
local tbl1 = {"hello", "world", "foo", "bar"}
local tbl2 = {"hello", "world", "foo", "bar"}
local tbl1reference = tbl1
table.insert(tbl1, "test")
for _, v in ipairs({tbl1, tbl2, tbl1reference}) do
print(table.concat(v, ", "))
end
tbl1 and tbl1reference hold the same exact table in memory and tbl2 does not, even if it has the same values in the same positions. Changes made to tbl1 or tbl1reference will affect tbl1 and tbl1reference.
##Value
However things like booleans and numbers are passed simply via value.
local _string = "hello"
local _string_value = _string
_string = "world"
print(_string_value)
local bool1 = false
local bool1_val = bool1
bool1 = true
print(bool1)
print(bool1_val)
Even though _string_value was set to _string, both variables have different memory and modifying one value does not change the other.
#Final product
local numb = game.Workspace.Numb
local function example()
while numb.Value == 0 do
print("same value")
end
print("value = 1")
end
example()
######Hopefully this answered your question, and if it did, then don't forget to hit that "Accept Answer" button. If you have any other questions, then feel free to leave them down in the comments.
5 comments
is your "data" variable not changing? If not then I can answer
yes
So the issue is that the data variable isn't updating?
yea
If i helped you out can you please accept my answer? It means a lot