Firing a remote event at a certain clocktime problem

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.

2 Likes

Is TimeOfDay set to 18 by default or are you changing it from another script?

If you’re changing it from another script are you checking TimeOfDay whenever the TimeOfDay changes?

Also try putting prints to debugging and make sure the time is exactly 18.

No, there is a day/night cycle going on, and i want it when it hits 18:00 i want it to fire a remote event.

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:

if game.Lighting.ClockTime == 18 then

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)

That should work for you.

I tried this but didn’t work aswell.

Try adding a print(game.Lighting.ClockTime) before the conditional to make sure it’s actually hitting 18.

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)
1 Like

Did not work unfortunately, i don’t know why not.
No errors nothing showing up.

1 Like

You need to code it to change the time continuously bud.

Can you maybe show us the cycle, and also the Explorer tab with the script(s)?

l = game:service("Lighting") 
while true do 
	wait(0.2)
	l:SetMinutesAfterMidnight(l:GetMinutesAfterMidnight()+.1)

end

the day/night cycle

Maybe try something like this…

if game.Lighting.TimeOfDay - 18 <= .25  then
 game.ReplicatedStorage.Events.TestEvent:FireServer()
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

Of course, you can adjust it to your liking.

I don’t get this code, could you explain it to me?

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.

The day/night cycle is not the problem here…

Maybe not now, but it will be. I suggest you read what I said in the post with the code.