Checking if number is between 2 sets of data

I’m trying to make this so if it’s between 10pm and 6am the Speed variable is 0.75, otherwise it stays at 0.5

if Lighting:GetMinutesAfterMidnight() <= 6 * 60 and Lighting:GetMinutesAfterMidnight() >= 10 * 60 then
	Speed = 0.75
else
	Speed = 0.5
end

I kinda know why this isn’t working, as at midnight it would go back to 0 but not sure how to go about fixing it

1 Like

With this section of code, you are trying to compare if the time is before 6:00 AM while also being after 10:00 AM (no overlap, so it never happens) since you are using an and, and 10:00 PM is actually 22:00 (12 + 10).
To correct this, you can use an or instead.

if Lighting:GetMinutesAfterMidnight() <= 6 * 60 or Lighting:GetMinutesAfterMidnight() >= 22 * 60 then
	Speed = 0.75
else
	Speed = 0.5
end
4 Likes