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

How to do that if a minute passed, remove 1 from the minute value?

function doClock(undif)
    if debounce2 == false then
        local undif = 0
        local debounce2 = true
        local DefaultTimeMinutes = mapStorage.DefaultTimeMinutes.Value
        local MinutesLeft = DefaultTimeMinutes
        local SecondsLeft = (MinutesLeft * 60) - 1
        local MinutesLeft = MinutesLeft - 1
        while SecondsLeft ~= 0 do
            local SecondsLeft = SecondsLeft - 1
            -- i wanna check if a minute passed, remove 1 from the minute value
            wait(1)
        end
    end
end

Any idea why on how to do that if a minute passed, remove 1 from the minute value? (as said on the comment)

1 comment

0

So I used delay to not stop the entire script while waiting becuase you not only have to subtract seconds but minutes.

1 answer

✓ Accepted answer

Just add a delay() timer. When a certain time passes, an function will execute.

local minutesLeft
local secondsLeft

function removeMinutes()
      minutesLeft = minutesLeft - 1
      print(minutesLeft.. " minutes and: " .. secondsLeft.. " seconds left.") -- Prints the time left
end
function removeSeconds()
      secondsLeft = secondsLeft - 1
	print(minutesLeft.. " minutes and: " .. secondsLeft.. " seconds left.") -- Prints the time left.
end

function doClock()
        local DefaultTimeMinutes = mapStorage.DefaultTimeMinutes.Value
        local MinutesLeft = DefaultTimeMinutes
        local secondsM = MinutesLeft * 60
        delay(1, removeSeconds())
        delay(60, removeMinutes())
end

So what I just made it's use a function called "delay()" that when certain times passes (in seconds, first argument), then a callback will be fired, in this case the functions.

Hope it helped.

1 comment

0

You don't need t print the time left, but it was just to prove the point to you.

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