if game.Lighting.ClockTime == 17.9 then
print("0H NO")
end
I was trying to make a script to detect the Clocktime of lighting but it doesn’t work for me. It is a local script
if game.Lighting.ClockTime == 17.9 then
print("0H NO")
end
I was trying to make a script to detect the Clocktime of lighting but it doesn’t work for me. It is a local script
while true do
task.wait()
if game.Lighting.ClockTime >= 17.9 then
print("0H NO")
end
end
But if it is repeated many times the print will continue and never stop
I think you should try
terminate = False
while terminate = False do
task.wait()
if game.Lighting.ClockTime >= 17.9 then
print("0H NO")
terminate = True
end
end
Since there is a variable, it should only print once instead of many times.
Hope this helps!
Edit:
Forgot to move the variable outside. (Oops…)
game:GetService("Lighting").Changed:Connect(function()
if game:GetService("Lighting").ClockTime == 17.9 then
print("0H NO")
end
end)
I think this’ll work but I’m not too sure. Worth having a try though!
Then use a break statement to break out of the loop.
The issue here is that when indexed, ClockTime is not going to be equal to 17.9, even when set to 17.9. It will be read as 17.899999618530273
or something crazy like that. Instead of looking at ClockTime, you should instead index TimeOfDay. So an equal check in terms of TimeOfDay would be like this:
if game.Lighting.TimeOfDay == "17:54:00" then
print("0H NO")
end
TimeOfDay is a string so it can be a little bit harder to use, but it’s nice to index, unlike ClockTime.
Hope this helps!
Edit: Grammar
Fine, I’ll provide a solution with some effort behind it.
local Lighting = game:GetService("Lighting")
local Connection
Connection = Lighting.LightingChanged:Connect(function(Sky)
if Lighting.ClockTime >= 18 then
print("Time has passed 6PM.")
Connection:Disconnect()
end
end)
https://developer.roblox.com/en-us/api-reference/event/Lighting/LightingChanged
You’ve likely never heard of this event before.
You can circumvent double floating point precision inaccuracies via rounding.
if (math.round(Lighting.ClockTime * 10) / 10) == 18 then
--Do code.
end
Sure, but I would still recommend using TimeOfDay, since it represents the same thing as ClockTime but in a way that requires less work to read, not to mention more accurate. Rounding in this case seems more work than necessary.
Any amount of additional accuracy is negligible. “TimeOfDay” is unfavorable as it’s a string value and thus you cannot perform math/mathematical comparisons with it unless you otherwise reformat it as a number value (which is what ClockTime is).
The solution to this is going to depend on how you are incrementing your clock. Solutions using == may never find a match if your clock increment isn’t landing on the value.
You could use a range and triggered variable to prevent repeats.
if not evening and game.Lighting.ClockTime > 17.9 and game.Lighting.ClockTime < 18.5 then
evening = true
--this will trigger once after 17.9 assuming your clock doesn't skip ahead past 18.5
--do evening stuff
--set evening to false somewhere else in the script for the next day cycle
end
This is kind of sloppy but it would work, unless you have a huge time increment, like if your clock jumps ahead hour by hour. Each 6 minutes is .1 hours.
If you know your clock cycle increments you could use the exact match method. If you tween the time you’ll probably never get a match.