I did have a previous boost system however the boost continued to run even after they are offline. Boosts are developer products that players can buy over and over, having different tiers of boosts. I managed to make a system that uses tick() to record when the player joins, and when the player leaves. Using this info I used it to record playtime, but how can I use this info to decide if a player still has a valid boost? How could I use os.time in order to achieve this?
You don’t really even need os.time in this instance.
Just create a script that runs while the player is in the game, that decreases their time remaining with the boost, until they leave. You can do this by using a loop.
You can use DataStores to save how much time they have left, and start the loop timer, counting down from where they left off when they rejoin.
For my daily rewards system which is similar to this, I save the player’s os.time() everytime they join.
This then allows me to tell how long it’s been since they were gone which can be done as such:
local LastLogin = TheDataSave --Which would be a os.time()
local Seconds = os.time() - LastLogin --How many seconds since last login
local Minutes = Seconds / 60 --How many minutes since last login
local Hours = Minutes / 60 --How many hours since last login
Then you can have another datastore which manages how much time is left on the boost, you could save the time remaining on the booster if there is time remaining when the player leaves and then compare the time remaining on the booster to their last login times as shown above.
Couldnt this be cheated? For example, before the loop goes back around, couldnt they leave and rejoin? Assuming the loop isn’t every 1 second (I prefer to not make this the case maybe because of performance?)
Oh i see, thanks for the insight! I will mess around with this
You don’t really need to decrease the boost on any faster intervals than 20 seconds, and you only need to save to the DataStore when the player leaves if you use DataStore2’s method of saving. I don’t really think this would cause any performance problems.
You could also implement os.time as Complextic mentioned. It’s really a matter of preference.
I’m sure you already know this, but if you do use os.time, make sure to do it on the server, which returns values in UTC time. If you do it from the client, it will return the local time on the players machine, which can easily be tampered with, leading to obvious problems.