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

os.time() not working properly as i want it?

Asked by 2 years ago

I'm trying to print a string when the time when the game starts is equal or higher than the time 5 seconds from when the game starts.

But it's not working as expected, maybe i'm just silly here but i don't know.


local oneSecond = 1 local oneMinute = oneSecond * 60 local oneHour = oneMinute * 60 local oneDay = oneHour * 24 local oneYear = oneDay * 365 while wait() do local secondsOs = os.time() if secondsOs >= secondsOs + (oneSecond * 5) then print("Reward is up!") end end

1 answer

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago
local oneSecond = 1

local oneMinute = oneSecond * 60

local oneHour = oneMinute * 60

local oneDay = oneHour * 24

local oneYear = oneDay * 365

while wait() do

    local secondsOs = os.time() -- It's on this line!! (I think)

    if secondsOs >= secondsOs + (oneSecond * 5) then

        print("Reward is up!")

    end

end

So, I think it's because it's updating every wait()- oh, and also using wait() is a very bad idea!!- the secondsOs is also being updated so every wait() it checking if the current secondsOs is higher than itself + 5 seconds. Do you understand? So you need to do:

local oneSecond = 1

local oneMinute = oneSecond * 60

local oneHour = oneMinute * 60

local oneDay = oneHour * 24

local oneYear = oneDay * 365

local secondsOs = os.time() -- Not changed

while wait() do
    local currentOs = os.time()

    if currentOs >= secondsOs + (oneSecond * 10) then

        print("Reward is up!")
    else
        print("pu si draweR") -- That's Reward is up backwards

    end

end

instead. (I think)

Ad

Answer this question