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.
01 | local tbl 1 = { "hello" , "world" , "foo" , "bar" } |
02 | local tbl 2 = { "hello" , "world" , "foo" , "bar" } |
03 | local tbl 1 reference = tbl 1 |
04 | table.insert(tbl 1 , "test" ) |
06 | for _, v in ipairs ( { tbl 1 , tbl 2 , tbl 1 reference } ) do |
07 | print (table.concat(v, ", " )) |
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.
01 | local _string = "hello" |
02 | local _string_value = _string |
07 | local bool 1 _val = bool 1 |
Even though _string_value
was set to _string
, both variables have different memory and modifying one value does not change the other.
Final product
1 | local numb = game.Workspace.Numb |
3 | local function example() |
4 | while numb.Value = = 0 do |
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.