The problem here is the fact that you wrongly assume that the Subscribers variable is a reference to the property of the Subscribers IntValue/NumberValue.
To solve this problem, you would have the variable 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, functions are passed by reference.
local f1, f2, f1ref
f1 = function()
for i = 1, 10 do
print(i^2)
end
end
f2 = function()
for i = 1, 10 do
print(i^2)
end
end
f1ref = f1
f1ref and f1 have the same exact function in memory, and f2 is a different function from f1 even if it has the same exact code, indentation, and line count (not that indentation would mean anything significant in Lua, but just to point out the similarities).
##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. No prize for guessing what happens with the boolean values.
#Final product
local player = game:GetService("Players").LocalPlayer
local Subscribers = player.leaderstats.Subscribers
Subscribers.Changed:Connect(function(subCount)
if subCount >= 50 then
player.PlayerGui.ComputerGUI.ComputerGui.CreateTier2Video.Visible = true
end
end
Notice the Changed event. You only need to check when the value changes. Not every two seconds.
######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.
2 comments
Not sure how leaderstats work but try to add a ".Value" in Subscribers (line 6) (Subscribers.Value)
There’s no need for it to be in a loop, also cut down the referencing, targeting an instance by one line through multiple descendants isn’t a good idea