Get each 5 minutes that has been passed

Is it possible to get how many 5 minutes have been passed since last login?

local t = os.time()
	
local w = 5
	
task.wait(w*2)
	
local v = os.time()
	
for i = 1 , 3 do
	if math.abs((t-v))>=5 then
		print("Since 10 seconds has passed, this would mean 5 seconds have been passed twice.")
	end
end

You could use something like tick()

local lastLogin = tick()  -- you could get this from a datastore that was saved before the player left
task.wait(610) --example amount has passed
local currentTime = tick() --get the current time
local secondsPassed = currentTime - lastLogin -- get the diffrence in seconds
local fiveMinuteIntervals = math.floor(secondsPassed / 300) -- calculate the 5 minutes intervals
print("Number of 5-minute intervals passed since last login:", fiveMinuteIntervals)
1 Like

Is there a way to check 3 times? Like for each 5 minutes in 3 iteration loop, for eaxmple if 10 minutes has passed since player left, print a statement twice but not the third time since 15 minutes has not passed.

Something like this?

local lastLogin = tick()
task.wait(601) 
local currentTime = tick()

local secondsPassed = currentTime - lastLogin
local fiveMinuteIntervals = math.floor(secondsPassed / 300)

for i = 1, 3 do
    if i <= fiveMinuteIntervals then
        print("5-minute interval " .. i .. " has passed since the player left")
    else
        break
    end
end

Yeah, and to be clear, 10 minutes interval would be math.floor(secondsPassed / 600)?

yes thats correct

local intervalMinutes = 10
local intervalSeconds = intervalMinutes * 60 -- 10*60=600
local lastLogin = tick()
task.wait(601)  -- Example wait time
local currentTime = tick()

local secondsPassed = currentTime - lastLogin
local minuteIntervals = math.floor(secondsPassed / intervalSeconds)  

for i = 1, 3 do
    if i <= minuteIntervals then
        print("10-minute interval " .. i .. " has passed since the player left")
    else
        break
    end
end

1 Like

I found out a way to do an iteration check with this, but is there a way to get rid of that continue statement and without the need of a table?

local function _solveHowManyLehmonsToDropFromSeconds(seconds: number)
	local seconds = os.time()-601
	local currentTime = os.time() 
	local secondsPassed = currentTime - seconds 
	local tseconds = 300

	for t,v in {"d","f",'v'} do
		tseconds *= t
		if tseconds == 300 then continue end
		print(math.floor(secondsPassed/tseconds))
	end
end

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.