Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would I change the Lighting.Timeofday property using a script?

Asked by
Zikelah 20
5 years ago
Edited 5 years ago

Im trying to make a script change the timeofday variable inside of Lighting. I have been searching on the dev page but I found nothing.

This is the code I tried to do this with:

local Lighting = game.Lighting

while true do 
    Lighting.TimeOfDay = Lighting.TimeOfDay + 15
    wait(300)
end
--this *REGULAR* script is in ServerscriptService

can someone help me figure this out?

2 answers

Log in to vote
0
Answered by
2ndwann 131
5 years ago
Edited 5 years ago

Perhaps you should do this:

local Lighting = game:GetService("Lighting")

local TimeIncrement = 1 -- Time starts at 0100h
while true do
    if (TimeIncrement < 24) then -- ClockTime uses military time so we have to check if TimeIncrement has gone past 24
     TimeIncrement = TimeIncrement + 1
    else
         TimeIncrement = 1 -- if TimeIncrement is past 24, reset it to 1, and the process begins again
    end
    Lighting.ClockTime = TimeIncrement -- set the time to TimeIncrement

    wait(1) -- adjust this to make the day/night cycle faster or slower
end

--this *REGULAR* script is in ServerscriptService

I hope it helps.

0
woah Zikelah 20 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

Looking at the Lighting.TimeOfDay wiki page I saw this piece of text.

Value Type: string [...] A 24 hour string representation of the current time of day used by Lighting. [...] Using TimeOfDay requires the time to be normalized and a string formatted:

In your code you attempt to add 15 to the TimeOfDay. Since the TimeOfDay property is actually a complex string, this will not work as intended. It seems like every 300 seconds you want to progress the time of day by 15 minutes (1/3 timescale nice). Let's tweak the posted example on the wiki (the third code box) to get what we want.

local Lighting = game.Lighting
mam = Lighting:GetMinutesAfterMidnight() -- I shortened the variable the wiki was using.
-- Also we may not want to start from zero, but where you set it in the studio.
while true do
    wait(300) -- We wait 300 seconds as before.
    mam = mam + 15
    Lighting:SetMinutesAfterMidnight(minNorm)
end
0
It is saying that minnorm in unknown Zikelah 20 — 5y

Answer this question