@captan40000 (Captan) posted a new topic, subject "Issue with animating Lighting.TimeOfDay". It read:

   I'm currently trying to make Lighting.TimeOfDay animated. I've tried, and it sort of works, but stops at the incorrect time.  
    Code:
    [code] 
        for Number = 20, 14.30, -0.1 do
        			game.Lighting.TimeOfDay = Number
        			task.wait(0.05)
        		end
        
    [/code]
      *[CLI]: Command Line Interface

@Ready2XD (Ready) replied

    What do you want to achieve???
      *[CLI]: Command Line Interface

After which, @captan40000 (Captan) added

    captan40000:
    
    > I'm currently trying to make Lighting.TimeOfDay animated.
    
    Please read before replying. If it isn't clear, I want time of day to get animated from 20:00:00 to 14:30:00
      *[CLI]: Command Line Interface

So @Ready2XD (Ready) replied

    I did read it but i don't understand it
      *[CLI]: Command Line Interface

After which, @Ready2XD (Ready) added

    That's working, I don't know what's the problem
      *[CLI]: Command Line Interface

To which @Ready2XD (Ready) replied

    ohhhhhhhhhhhhhhhh i understand
      *[CLI]: Command Line Interface

Then @Imperiector (Imperiector) said

    lighting.TimeOfDay is a string, use lighting.ClockTime instead
      *[CLI]: Command Line Interface

@Ready2XD (Ready) replied

    Yes, so maybe this will work:
    [code] 
        for Number = 20, 14.30, -0.1 do
        	game.Lighting.ClockTime = Number
        	task.wait(0.05)
        end
        
    [/code]
      *[CLI]: Command Line Interface

So @Disrespectly (Infa) replied

    The issue is with Lua, called floating point imprecision.
    
    As you're constantly counting down from 14.30 in intervals of 0.1, due to imprecision with inaccuracy, it'll always end up close to 14:30, but never 14:30 entirely.
    
    There's numerous ways to fix this, but namely, I'd recommend TweenService, which can accomplish the same job without a loop and is overall easier to use for your needs as well as customizable.
    
    Below is an example of using TweenService to accomplish what you originally wanted to do, with comments to follow.
    
    We'll be using ClockTime instead, as TimeOfDay is a string while Clocktime accepts integers. The only difference will be that instead of following formatting like “14:30”, it'll be integer based, so our equivalent of 14:30 will be 14.5.
    [code] 
        local TweenService = game:GetService("TweenService") --get tweenservice
        local TransitionTime = TweenInfo.new(1.5) --you can change the 1 to how long you want the tween to take, there's more settings, but this is the most basic format
        local Goal = 14.5 --the desired clocktime (results in 14:30 timeofday)
        TweenService:Create(game.Lighting, TransitionTime, {ClockTime = Goal}):Play() --create the tween with our assembled variables and play it
        
    [/code]
      *[CLI]: Command Line Interface

After which, @captan40000 (Captan) added

    It appears to work but the Tween is on a loop. How do I fix this, I think it's the TweenInfo's Repeat Loop.
      *[CLI]: Command Line Interface

@captan40000 (Captan) replied

    Nope. Something is wrong with the script, I made the Repeat Loop false yet It still does it.
      *[CLI]: Command Line Interface

After which, @captan40000 (Captan) added

    My bad, It ended up being another script. Sorry.
      *[CLI]: Command Line Interface

Then @Ready2XD (Ready) said

    did you even try this:
    [code] 
        for Number = 20, 14.30, -0.1 do
        	game.Lighting.ClockTime = Number
        	task.wait(0.05)
        end
        
    [/code]
      *[CLI]: Command Line Interface

After which, @Disrespectly (Infa) added

    Not a problem! If you need any further help, I'll keep an eye on the thread.
    
    If it works as intended, go ahead and mark the answer as the solution so the thread is concluded.
      *[CLI]: Command Line Interface

@umamidayo (dayo) replied

    This would be the best option since TweenService precisely smoothens changes.  
    Best of all, it's easy to use and highly configurable.
      *[CLI]: Command Line Interface


{'source': 'discourse', 'url': 'https://devforum.roblox.com/t/issue-with-animating-lightingtimeofday/1623300', 'title': 'Issue with animating Lighting.TimeOfDay', 'views': 181, 'has_accepted_answer': True, 'word_count': 499, 'like_count': 4, 'reply_count': 11, 'participant_count': 5, 'posts': 15, 'tags': '', 'author': '@captan40000 (Captan)', 'participants': '@captan40000 (Captan), @Ready2XD (Ready), @Imperiector (Imperiector), @Disrespectly (Infa), @umamidayo (dayo)', 'image_url': [None], 'created_at': '2022-01-11T22:24:19.836Z', 'last_posted_at': '2022-01-11T23:16:57.100Z'}