I want to able to edit a players data if they aren’t in a server or even on another server.
Basically my idea is I want players to send messages to each other (not Roblox chat, custom messaging) And I know if MessagingService but I don’t think that will work fully how I want. Problem is if a player who you are sending to isn’t in the game, I don’t know what to do. I only know of how to edit Data of players who are within the game at that time. So how can I make changes to a players data when they are offline? I’m using DataStore2 btw. Is there any sort of function that can just return any users data and allow edits to be made?
How I am saving/Loading data
function DataManager.Load(player)
local PlayerDataStore = DataStore2(DataName, player)
local PlayerDataTable = PlayerDataStore:GetTable(DefaultData)
local PlayerDataFolder = Converter.Convertr(PlayerDataTable) -- Convert to physical instances
PlayerDataFolder.Name = 'PlayerData'
PlayerDataFolder.Parent = player
end
function DataManager.Save(player)
if player:FindFirstChild('PlayerData') then
PlotManager.Save(player)
local PlayerDataStore = DataStore2(DataName, player)
local PlayerDataTable = Converter.Convert(player.PlayerData)
PlayerDataStore:Set(PlayerDataTable)
end
PlotManager.Clear(player)
end
DataStore2 does not have native support for accessing offline player data, it would require forking the module. If you want me to help you with that let me know with a reply.
I’m kinda just looking over my current data store setup, is how I’ve done it sufficient? I’m tryna follow tutorials on saving multiple keys and what not, which I don’t think I’m doing but all tutorials only show how to save 1 value, while mine has well over 20-30 values and tables to save across
A sort-of hacky solution to your problem would be to retain messages to offline players in a general datastore. When the recipient joins the game, a datastore check would occur and would remove the message from the system and put it under the player. It’s sort-of hacky because if messages are sent to players who don’t ever play the game (ever or again), they would stay in the datastore forever and a build-up would result in you being forced to inevitably create more general datastores.
Since DataStore2 relies on the actual player objects, you cannot change the data directly within DataStore2 without modifying the module to accept userIds
You would need to figure out how DataStore2 stores its key values to the actual DataStore service (I presume it uses the player’s userId in some form). From there you can retrieve data by directly referencing the key to the real DataStore service.
Don’t use datastoe2, from personal testing with it I found it to be unreliable despite what others have said, besides normal datastoring works just fine with a simple function checking for the player incorrectly leaving.
local dss = game:GetService("DataStoreService");
local data = dss:GetDataStore("main");
function editdata(playersid)
local userdata = data:GetAsync(playersid); --// playersid is the userid of a player
userdata.Coins = 1000 --// the edit
data:SetAsync(playersid, userdata);
end