Is there a way to change a players data value while the player is not in game?

basically am trying to regenerate a player’s mana while there not in game
say they left with 50 mana
after 10 minutes they join back they will have 60 mana
every minute they get 1 mana

will this be possible? thx in advance :smiley:

Yeah, maybe, not sure tho. 30 ch ars

Yes, just have a ServerScript call DataStore:SetAsync/DataStore:UpdateAsync with the player’s key and the value incremented by 10, this will only work if stamina is stored in a DataStore though.

She’s asking if you could do it if the server is not running or the player is not ingame

How I would go about solving this is store the time they left at (tick, os.time, etc.) and when they join, subtract the current time from the one you previously saved and that will tell you how many seconds the player was not in-game.

From here you can do your own conversion, like every 10 minutes they get X amount of mana.

4 Likes

Yes, and I gave a solution, they don’t have to be in-game for you to call SetAsync/UpdateAsync with their key, just save their key while they’re present in the game and then have some script wait some period of time which actively restores their mana for when they return.

This will only work for a single server instance.

Not if you save it under a DataStore.

Yes, but how will the script run even if servers are off or somthin?

Yes, a DataStore would be necessary. You didn’t mention one so I wasn’t sure if you planned to include one or not.

Yeah, sorry lol. When I said store the time they left, I meant under a DataStore.

You mean if everyone leaves and the server instance ceases to exist? Well then I’d blame poor player retention but you could solve this through a webhook (likely too much work though), the feature would just favor player’s who entered servers which survived longer. A time since last played like the above post suggests would also work.

hm good one, but what if webhooks go down, that’s why We will use para’s solution. os.time() in datastore

This begs the question, after the last player leaves a server, how long does the server stay active? Couldn’t you update the entire datastore once the server is about to close??

Well you always have backup webhooks, but ultimately host your own, and downtime is a common problem shared by just about everything.

But will take too much time to setup and not that efficient. is.time is better

Good one, but how will the last player get his mana orbs D :

Yes, but future updates while the server no longer exists wouldn’t happen, in other words if the plan was to have the player be awarded 10 mana for each hour they aren’t in the game but the server only lasts an additional hour after they leave then only 10 mana will be replenished even if the player doesn’t come back for many hours since they left.

Recording the time since they left and then subtracting that from the time at which they rejoined is the better option here.

1 Like

You could also have bots in each server keeping them alive by making sure a server never reaches 0 players.

I’d have to agree with you, calculating the difference in time with a multiple seems like the best, and most lightweight, route to go.