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

How do you make a value increase slowly?

Asked by 4 years ago

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

Log in to vote
0
Answered by
Mayk728 855 Moderation Voter
4 years ago
Edited 4 years ago

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
1
ok thanks, but how do I make it to where it does this for the TimeofDay part? BadPiggie411 47 — 4y
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. Mayk728 855 — 4y
0
ok BadPiggie411 47 — 4y
Ad
Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

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.

0
That wrong. It used to be :GetMinutesAfterMidnight() Mr_m12Ck53 105 — 4y
0
do you know how to do this but with, a normal value BadPiggie411 47 — 4y
Log in to vote
0
Answered by 4 years ago

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.

Answer this question