How to figure out if a certain time has passed

so what i am trying to do is create a jail system similar to ridgeway or new haven county where when you get jailed, you have a timer. example:

i get booked for 10 minutes.
i leave for 5 minutes
and it says 5 minutes left

so, how would i do something similar to that or how would i figure out how much time has passed

When you get sent to jail, get the time using os.time. When I leave the game, use os.time again, and subtract the start time from it to get the amount of time you have been in jail.

1 Like

You could use wait but generally it is unreliable.
Use tick time.
Here’s an article:
Tick article here.

1 Like

So, it would just be

--when jailing 
plr.Data.JailStartTime = os.time()
plr.Data.JailTime= sentenceTime -->> 30

-- when joining 
plr.Data.JailTimeLeft = os.time() - plr.Data.JailTime
--when jailing 
plr.Data.JailStartTime = os.time()
plr.Data.JailTime= sentenceTime -->> 30

-- when leaving
plr.Data.JailTimeLeft = os.time() - plr.Data.JailTime
-- upon joining, if there is time left, send them to jail and wait out the time
1 Like

So, what will it be when 30 mins has passed? 0 or a negative?

Am I supposed to multiply sentence time by something? Because about 30 minutes have passed nd its still above 0

I think you should check if the specified time has passed like this:

local JailTime = 10 * 60

plr.Data.JailStartTime = os.time()
plr.Data.JailTime= sentenceTime -->> 30


plr.Data.JailTimeLeft = os.time() - plr.Data.JailTime
if plr.Data.JailTimeLeft >= JailTime then
	print("Jail time is over")
else
	print("Jail time is not over yet")
end

Update, I figured it out. Thank you all for trying to help!

1 Like