Posting this here in scripting support before I post a bug report, as I’m not sure if it’s actually a bug, or just some sort of programming error on my part. Any fixes or feedback would be greatly appreciated.
What do you want to achieve?
I want to change the clocktime property and then read it with the PropertyChanged signal.
What is the issue?
ClockTime changes via the while loop, but when the PropertyChanged signal fires, the ClockTime property still outputs what it was initially set to in the explorer / properties window, even after being changed by the while loop.
What solutions have you tried so far?
I have tried changing the speed of the while loop and changing the amount that the time changes every loop. I have also tried running this code in a different place, which resulted in the same issue.
Code below:
local lighting = game:GetService('Lighting')
local clockTime = lighting.ClockTime
coroutine.wrap(function () --New thread for day/night cycle
while wait() do
lighting.ClockTime = lighting.ClockTime + 0.1
end
end)()
lighting:GetPropertyChangedSignal('ClockTime'):Connect(function()
print(clockTime)
end)
That’s because you are never returning the clock time, try3
local lighting = game:GetService('Lighting')
local clockTime = lighting.ClockTime
coroutine.wrap(function () --New thread for day/night cycle
while wait() do
lighting.ClockTime = lighting.ClockTime + 0.1
return lighting.ClockTime
end
end)()
lighting:GetPropertyChangedSignal('ClockTime'):Connect(function()
print(clockTime)
end)
Because you are getting the value of the ClockTime and not the Instance Holding that value, referencing the value only gives you the value and not the Instance, like this:
local Number = lighting.ClockTime -- by Default its 14.5 so we Number is equal to 14.5
lighting.ClockTime += .1 -- adds
print(lighting.ClockTime) --> 14.6 (Updated)
print(Number) --> 14.5 (Number was grabbed before the update)
so you should be doing:
print(lighting.clockTime)
which should print the actual time isince we are grabbing it directly from the LightingInstance
or if you want to keep the last value, you can do this:
print(clockTime) -- old time
clockTime = lighting.ClockTime -- changes to recent ClockTime
D’oh! This fixed it! Thank you! Seems totally obvious now! Took a break from programming for about 6 months due to work, so I’ve been a bit rusty lately!