Script Not Working as Intended

I have a script in place and it’s connected to game.Lighting:GetPropertyChangedSignal("ClockTime") event, the thing is when I’m comparing ClockTime it’s like it does not work.

I have it like this;

local function GetClockTime()
	return math.floor(LightingService.ClockTime)
end

if GetClockTime() >= 20 and GetClockTime() <= 6 then
    -- script runs
end

The thing is, the script never runs unless I put or and I’m confused because you’d think it’d work as expected since it’s giving the actual numbers and the ClockTime event would work like 20/21/22/23/0/1/2/3/4/5 since those numbers are less than six.

Any clue on why this isn’t working?

1 Like

change the and to an or and it should work

if GetClockTime() >= 20 or GetClockTime() <= 6 then
4 Likes

If you really think about it, how would you get a number which is greater than 20 but also less than 6?
It makes sense semantically (since this has to do with time), but not logically (since a number cant be greater than 20 and less than 6 at the same time)
You need to use the or operator instead of and

Yeah and I’ve done that and it causes errors because after the ClockTime hits 6 or like passes six then it keeps spamming the script that’s supposed to execute if ClockTime == 6 and if ClockTime >= 20.

1 Like

What if I did;

if GetClockTime() >= 20 then
    if GetClockTime() <= 6 then

    end
end

Would this work or no?

1 Like

Just like me and @CZXPEK stated, use or instead of and.

if (GetClockTime() >= 20 or GetClockTime() <= 6) then
end

Yes but the point is if I do that then the script will fire either way, it keeps happening in studio when I test it so will the way I put above work or not?

no, you’re checking if the clocktime is greater than 20 and suddently after you’re checking if its lower than 6

local function GetClockTime()
	return math.floor(LightingService.ClockTime)
end

if GetClockTime() >= 20 or GetClockTime() <= 6 then
    
end

by adding an or, 20+ and 6 and less numbers will pass by the statement

I don’t think you’re understanding how the or operator works in this place.