Wont print no as if clocktime is always within range

Code:

local TimeCheckDelay = 5;

local Lightning = game:GetService("Lighting")

coroutine.resume(coroutine.create(function()
	
	while true do
		
		print(Lightning.ClockTime)
		
		if Lightning.ClockTime <= 17.75 or Lightning.ClockTime >= 6 then
			
			print("123")
			
		else
			
			print("No")
			
		end

		task.wait(TimeCheckDelay)

	end
	
end))

Script wont script no at all as if the time is always in range

You need to change or to and, having or will make one or the other condition to be true and the total condition will always be true.

Lightning.ClockTime <= 17.75 and Lightning.ClockTime >= 6 then
Untested guess …

1 Like

works but now it spawns them during the day too its only supposed to spawn them during night

They are spawning during the day because you have the range during the day. You can configure the time until the range is right for you.

1 Like

which time would not be during day

I don’t work with lighting that much, but I’m pretty sure the time is based on a 24-hour system. You can go into lighting to change “ClockTime” and see at which point in time will the day be night.

yeah but the problem is that it resets from 24 to 0

As mentioned in the last reply, the time is based on a 24-hour system. You can add more conditions that will satisfy the code you are trying to accomplish.

if Lightning.ClockTime >= 17.75 and Lightning.ClockTime <= 24 or Lightning.ClockTime >= 0 or Lightning.ClockTime <= 6 then

would this work?

This will return back to the old problem you have where the code will always be in range. I suggest adding parenthesis to produce the correct boolean. For example

if (condition == true and condition2 == true) or (condition3 == false and condition4 == true) then
     -- do code here
end

what do parenthesis do in this situation?

Parenthesis are like those parenthesis in order of operation in math. Using them will allow the conditions to be checked first. They could also be used to visually see the code better for readability.