Is there anyway to change a value in a DataStore for everyone, including those who are offline?

So, I have a timer script that changes a value once it goes off for everyone. However, it’s a saving value, and if a player is offline at the time that the timer goes off, the value doesn’t change for them. Is there anyways to change a value inside of a DataStore for every player?

If needed, I can give my DataStore script.

You can store every userId of users which join the game in a table and save it to another DataStore but under one key (ex. ‘userids’) , then get that userIds table with GetAsync(‘userids’) and do

for i,v in pairs(userIdTable) do
	TimerStore:SetAsync('player_'..i,time)
end

The table would be something like this

local userTable = {
	["useridhere"] = "wheteveryouwantitsmeaningless", 
	["useridhere2"] = "wheteveryouwantitsmeaningless",  
	etc. 
}

Also probably there’s a better way.

You can change data in DataStores while players are offline but you can’t apply the update to everyone since there’s no way to query all existing keys with values in a DataStore right now. You will have to find a way to do this timer differently. Do be specific: what is this saving timer for?

The way I do it in my games is if I need to save an expiring value to a DataStore and the player is not in the game currently I track when they last logged in. When they next log in, I get the current time and calculate how long they’ve been away from the game, then apply that difference to the saved time value. If the saved time value is negative then they lose their effects and consequently data related to that saving timer. That or I simply don’t count it down when they leave and only render the timer active for the duration of their gameplay.

@CAROR567 Wouldn’t recommend. This solution isn’t scalable for large games and solutions should aim to scale. Games that have many players will not be able to fit all their playing players’ UserIds within 4MB worth of data. It’d be a different story if we had access to a panel to manage data in our DataStores but we don’t so you shouldn’t.

Btw if you do that ALWAYS make sure to delete/blur out the data key because people can use it to give themself stats

Only if your game is structured badly enough that a client can call a remote and force data through to the server without validation. Blurring out keys is only really necessary for external APIs where you need a key to make a successful call. DataStores are server-sided so knowing the keys being used for data is irrelevant and doesn’t contribute towards self-data manipulation.

The timer is meant to give new jobs for people in a job system, but it also resets the value of how many times a job has been completed to 0. (This is because there’s a limit of 2)

(Edit: it’s simply a 24 hour clock that runs everyday AND IS SERVERSIDED)

If the timer needs to be active when the player is offline, then yeah, I would just save the remaining time as well as when they last logged in. When they next log in you can get the current time and compare that to when they last logged in, find how much time elapsed between their last and current log in then adjust the timer accordingly. If the timer goes negative then accordingly adjust their job data. If there’s still time left then you can just load up their job data and then count it down in the current server.

If the timer is global then I still need far more explicit details to find out your exact use case. It seems very esoteric and I’m still working with vague information. My assumption is that you have a per-player timer going on here to manage their expiry information.

They can go into their own game and use the key to change their stats on the other game. It’s how games with multiple places inside of it for minigames and whatnot all have their stats connected.

That’s not how DataStores work. DataStores are per-game, not global, so your game’s DataStores are different from other games. Games that have multiple places are able to share and manage data because they’re within the same game. Please read up on how DataStores work!

Data Stores on Developer Hub

1 Like