Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do you make a value increase slowly?

I want to make my own Day/Night cycle, but I don't want to have to type each individual number I want it to. I can just make something like:

game.Lighting.TimeofDay

and then I could make it to where the time increases by 0:00:10 every second.

3 answers

✓ Accepted answer

This is probably going to be really slow, but you can adjust the wait time and how much the clocktime will increase, to your liking.

local Lighting = game:GetService('Lighting')

while wait(1) do
	Lighting.ClockTime = Lighting.ClockTime + .1
end

3 comments

1

ok thanks, but how do I make it to where it does this for the TimeofDay part?

0

TimeOfDay and ClockTime are the same thing, just a different value. ClockTime is just a number, while TimeOfDay is "00:00:00". It should do the same thing. I just prefer using ClockTime.

0

ok

There are many of these out there however I'll explain how they work. You could do it two ways, using a while loop or an until loop. I would use a while loop for this because it looks like you want this cycle to go forever.

To do this while loop you would do something like this:

while true do -- setting the middle part to true, essentially means it will go on forever.
	--put whatever you want to happen, here.
	wait() -- always have a wait inside loops unless there is an end to the loop like a for loop.
end

In your case you would want to do:

while true do
	game:GetService("Lighting"):SetMinutesAfterMidnight(game:GetService("Lighting"):SetMinutesAfterMidnight + .1)
	wait(1)
end

What this does is sets the time of day to the time of day before plus 10 seconds, every second.

2 comments

0

That wrong. It used to be :GetMinutesAfterMidnight()

0

do you know how to do this but with, a normal value

if you really want to use TimeOfDay so try this

while true do
	wait(1)
	
	local increase = 10
	local first = string.sub(game.Lighting.TimeOfDay,1,6)
	local num = string.sub(game.Lighting.TimeOfDay,7,8)
	local new = tostring(num+increase)
	game.Lighting.TimeOfDay = first..new
end

I extract to 2 strings and increase the latter by 10 then reassemble them again.

This discussion is preserved as it was. New answers, comments, and votes are closed.