So not anything hard in here, i just never worked with time stuff so i barely know how it works, i tried to do this but it doesn’t work for some reason, does anybody have a solution?
if game.Lighting.TimeOfDay == 18 then
game.ReplicatedStorage.Events.TestEvent:FireServer()
end
It basically fires a remote event every time the clocktime gets on 18:00.
If you’re not doing that, you should. Because if you won’t do that it would just check the TimeOfDay once. As i said try using prints and make sure the TimeOfDay actually hits 18.
TimeOfDay is a string and you’re comparing a string with a number, which won’t work. Not to mention that TimeOfDay would look like “18:00:00” 18 hours into the day
You can check the TimeOfDay like this:
if game.Lighting.TimeOfDay == "18:00:00" then
Or with the numeric measure, represented by a real number:
Are you checking every time the time of day is changing, or only when the script starts?
If you aren’t, you can create an event like so
game.Lighting:GetPropertyChangedSignal("ClockTime"):Connect(function()
if game.Lighting.ClockTime == 18 then
game.ReplicatedStorage.Events.TestEvent:FireServer()
end
end)
It works but it only works when i do :time 18 then it only does. (admin commands), i think there needs to be a specific part where it updates the time.
local lit = game:GetService("Lighting")
lit:GetPropertyChangedSignal("ClockTime"):Connect(function()
local Time = lit:GetMinutesAfterMidnight()
if Time==18*60 then -- multiply by 60 if you want in hours
print("Its night time")
end
end)
Uhh… even if the code worked, it would eventually just stop working, you’re just adding on time, and not resetting it when it reaches the limit, try this instead:
local Lighting = game:GetService("Lighting")
while true do
wait(0.01666666666)
Lighting.ClockTime = Lighting.ClockTime < 24 and Lighting.ClockTime + 0.001 or 0
end
It is basically just adding on ClockTime by 0.001 every 0.01666666666 seconds, and when it reaches the limit which is 24, it starts over, from 0 again. Like I said, adjustable, and still fixes future issues.