Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to count a value when the player is not playing game?

Asked by 3 years ago

In my game, I am adding a group rewards system, that gives you 200 cash every 4 hours, but if the player leaves the game the 4 hour countdown stops and when they join again allows them to get the reward. If I use datastores it saves the value when the player leaves, when they join again it goes to the value saved instead of to have been counting.

Is there a way to keep counting if the player is offline or not playing the game?

1 answer

Log in to vote
1
Answered by
HamBott 20
3 years ago

The widely adopted and best way to have a countdown continue while a player is offline is to store when the player logged off, and then when they log on, calculate what they should get by comparing when they logged off to now. In your case you would check how many 4 hours have passed and the current state of the 4 hour countdown.

0
just use os.time save there log off time then when they come back the new os.time will be the present and the other time will be the pass and when they get the award reset the datastore to the time that they collected it at coolmanHDMI 72 — 3y
Ad

Answer this question