Make data expire after an amount of time

Basically, I want to make the data expire after a certain length of time, for example, after 24 hours, the data should reset (0) or expire, however I’m not sure if that’s possible. If so, could you kindly explain? This is important for a project I’m working on, such as a daily mission. I’ve successfully saved the data and etc, but confused to make it save for only 24 hours.

It’ll be possible, but I won’t be able to help because I don’t got the time to try figure it out but you could try use os.time to check if its been 24 hours.

Deleting data will depend how you save your data, weather you’re using DataStore2 or ProfileService or just the basic Roblox DataStore

I’m sure someone will comment something that can help you!

2 Likes

Like @Modern_Developer2201 stated, you could save the time whenever they get data (using os.time). And when the player logs back on, you could check how long it’s been since they got that data (and if it’s been 24 hours or more you can set the data to nil).

This is just an elaboration on @Modern_Developer2201’s post.

For a mission, you can use the tick() number when adding a mission, and when reconnecting, use the difference between the current tick() and the saved one in order to find out how much time has passed.
If necessary, you can delete the data

1 Like

I’ve seen that you marked my post as the solution, did you manage to get it to work?

Yes, I did it using os.time() + the expiration time, and then saved that expiration time in the data to check, and then when loading the data, I made sure that the current time [os.time()] is less than the expirationTime in the saved data, and if so, set the values to that data’s value; otherwise, reset the values. It did, in fact, work.

You got that done very very quick lol. That’s good!

1 Like

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