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

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

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

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)

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