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

Making a script that prints text on certain time doesnt work?

Asked by 2 years ago

So I am trying to make script, that prints text on set time. I want it to print midnight on 00:00:00 of clock time and noon on 12:00:00. But for some reason, unknown for me, its not doing anything. Any idea what mistake am I doing.

function DayNightDoorCycle()
    while true do
        if game.Lighting:GetMinutesAfterMidnight() == 0 then
            print ("midnight")
        end

        if game.Lighting:GetMinutesAfterMidnight() == 720 then
            print ("noon")
        end
    end
end

1 answer

Log in to vote
0
Answered by
A_Mp5 222 Moderation Voter
2 years ago
local function DayNightDoorCycle()
    while true do
        if math.floor(game.Lighting:GetMinutesAfterMidnight()) == 0 then
            print ("midnight")
        elseif math.floor(game.Lighting:GetMinutesAfterMidnight()) == 720 then
            print ("noon")
        wait() -- it stopped due to server exhuast execution
        end
    end
end

Also, i reccomend using a function to check, like a getpropertychangedsignal or changed, as indefinite loops are't healthy. Also, you shopuld put a inf loop into a function, otherwise it will keep looping and the rest of the function lines won't run.

also, the values might constantly be changing in values, so i added math.floor()

Ad

Answer this question