Tell me if this is the wrong topic to put this post in.
I have a question about DataStores. If a new player joins server 1 and gets a DataStore called “PlayerData”, then when another player from server 2 accesses the DataStore “PlayerData”, will it be blank or return the data saved on server 1?
If you’re asking if the data is shared with other servers, then yes, it is. DataStoreService uses keys and with keys, you can choose a specific data store. Like for example, player statistics data stores use the player’s UserId for keys and if you mention that key, only that specific player’s data will be returned.
The first thing Roblox says about Data Stores is that they can be access within Places (not Experiences) or Servers
If that was the case where Data didn’t go to the other Server, it would effectively remove the usage of even having a DataStore in the first place, Servers aren’t a permanent thing, when everybody leaves the Server, or when Roblox goes down for maintenance, The Server will automatically close, meaning that your Data would be lost forever.
But then if you left the Server to do something, You would have to find that Server all over again which would be a pain,
(You get what I’m saying?)
It isn’t a Stupid Question, It’s just that It doesn’t make sense when you think about it more.
To explain this a little easier, datastores are stored in their own external (although still within Roblox) database. When a game server requests a datastore, it will send a request to Roblox’s datastore database with the game id and a key. Roblox will then return the relevant data (value) from the datastore it retrieved. This does inherently mean that the same data can be accessed from any server within the same game/experience. But you are right to be concerned with the potential for overwriting data, but it won’t be an issue in most cases and the documentation explains how to deal with those situations along with other limitations you may run into:
All data related to a specific player should always use their Player ID in the datastore at some point. This depends on the exact purpose of the DataStore and how you’ve organized it but it could be the datastore name, or key.
In most cases you’re going to create unqiue datastores per player. “PlayerDataStore_UserID” as an example name where “UserID” is the user’s ID instead of the text. The purpose of a DataStore is that when all players leave an instance of a game, it closes, and all data goes with it. DataStore’s exist outside that instance, and can be refrenced from other instances.
I just wanted to mention that naming a key with the user’s ID is no longer needed and not recommended.
Nowadays, you just use:
local dataStoreService = game:GetService('DataStoreService')
local specificDataStore = dataStoreService:GetDataStore('DataStoreName')
local playerData = specificDataStore:GetAsync(player.UserId) -- load data
specificDataStore:SetAsync(player.UserId,newData) -- save data
Although, you should also use pcalls to make sure that your data is actually loading correctly, as to prevent the small risk of data loss.