-
What do you want to achieve?
I want to know how to know if a value changed !
-
What is the issue?
The code only executes one time !
-
What solutions have you tried so far?
I have this code and I want to know if the year has changed for execute the code :
if Year % 4 == 0 then
LeapYear = true
else
LeapYear = false
end
Have a good day 
Hi! if you have a object that stores the value do this:
local ValueObject = ....
ValueObject:GetPropertyChangedSignal("Value"):Connect(function()
-- Code for when value changes
end)
1 Like
Hi! 
I have already just a variable named “Year”. 
Is it possible to do this without any ValueObject ? 
Well, to make it simple for yourself make that ValueObject. 
local Year = Instance.new("IntValue")
Year.Name = "Year"
Year.Parent = script
Year:GetPropertyChangedSignal("Value"):Connect(function()
-- Code for when value changes
end)
1 Like
I have do this but it does not work : 
local year = Instance.new("NumberValue")
year.Name = "Year"
year.Parent = script
year:GetPropertyChangedSignal("Value"):Connect(function()
if Year % 4 == 0 then
LeapYear = true
print("LeapYear")
else
LeapYear = false
print("NotLeapYear")
end
end)
while wait(1) do
Year = Year + 1
end
Hi!
I would recommend using IntValue over NumberValue, if you don’t use decimals in your “Year”.
When that is said, since you defined “Year” as a objectValue, you gotta say “Year.Value” instead of “Year”.
local year = Instance.new("NumberValue")
year.Name = "Year"
year.Parent = script
year:GetPropertyChangedSignal("Value"):Connect(function()
if year.Value % 4 == 0 then
LeapYear = true
print("LeapYear")
else
LeapYear = false
print("NotLeapYear")
end
end)
while wait(1) do
year.Value += 1
end
1 Like
Yes, but I need to do an infinite loop for definite the variable year ?
I’m not quite getting what you mean? 
1 Like
It works perfectly but I don’t know how you did it… can you explain? 
Sorry, I speak little english … 
Finally it does not work because I haven’t got the true variable “Year” I made ! 
Yea I can explain the script for you. 
local year = Instance.new("IntValue") -- We define our "year" variable to be a new "IntValue", which will contain numbers without decimals. Use "NumberValue" if you wish to have decimals.
year.Name = "Year" -- We set the name on our new ValueObject to be "Year"
year.Parent = script -- We set the parent on our new ValueObject to be the this script.
year:GetPropertyChangedSignal("Value"):Connect(function() -- We create a signal here, that will run everytime our ValueObject changes value.
if year.Value % 4 == 0 then
LeapYear = true
print("LeapYear")
else
LeapYear = false
print("NotLeapYear")
end
end)
while wait(1) do
year.Value += 1 -- We take our ObjectValue's Value, and says it should be it's current value + 1, meaning if our ObjectValue's current value is 2, then it will be 2+1 (year.Value +=1 is the same as year.Value = year.Value + 1, just shorter)
end
2 Likes
Thank you so much I’ve understand look at this
:
local year = Instance.new("NumberValue")
year.Name = "Year"
year.Parent = script
year:GetPropertyChangedSignal("Value"):Connect(function()
if year.Value % 4 == 0 then
LeapYear = true
print("LeapYear")
else
LeapYear = false
print("NotLeapYear")
end
end)
while wait() do
year.Value = Year
end
Can I ask why you set the year.Value to be Year? is it because you change “Year” elsewhere? 
1 Like
Yes it is exactly, you want to see ? 
Yea that would be nice, then we might be able to change the coding.
1 Like
Ah okay but it works like that, don’t worry! 
if Time == "00:00:00" then
Day = Day + 1
if Month == 1 or 3 or 5 or 7 or 9 or 11 then
if Day == 32 then
Month = Month + 1
Day = 1
end
elseif Month == 4 or 6 or 8 or 10 or 12 then
if Day == 31 then
Month = Month + 1
Day = 1
end
elseif Month == 2 then
if LeapYear == true then
if Day == 30 then
Month = Month + 1
Day = 1
end
else
if Day == 29 then
Month = Month + 1
Day = 1
end
end
elseif Month == 13 then
Year = Year + 1
Month = 1
end
end