Hey all! I have a script in ServerScriptService with all the DataStores in my game defined and all self updating - how can I "Re-use" this in other scripts by "SetAsyncing" data using that script without having to recall the DataStores?


local OilRigData       = game:GetService("DataStoreService"):GetDataStore("BestOilRigOverall")

local OilRigDataUserId = game:GetService("DataStoreService"):GetDataStore("BestOilRigOverallUserId")

local data            = 
{dataone              = OilRigData:GetAsync("BestOilRigOverall"),
datatwo               = OilRigDataUserId:GetAsync("BestOilRigOverallUserId")}

local OilRigConnection = OilRigData:OnUpdate("BestOilRigOverall", function(newValue)
    data.dataone = newValue
end)

local OilRigUserIdConnection = OilRigDataUserId:OnUpdate("BestOilRigOverallUserId", function(newValue)
    data.datatwo = newValue
end)

function game.ReplicatedStorage.RemoteFunctions.GetData.OnServerInvoke(player)
    return data
end

From another script I can "GetAsync" this data by Firing a RemoteFunction and print(data.dataone) but how can I use this (or a similar script) to Set Astnc the DS's in a similar way? Preferably I would like to do something like data.dataone = 122 if possible! :slightly_smiling:

Any tips/help appreciated. Thanks!

4 comments

0

I'm not exactly sure what you mean by your question. Could you elaborating a bit more or maybe provide an example?

0

Sure, I did! :) Let me know if it is still not clear!

0

I think OP wants it so that they don't have to do :GetAsync() every time they want to retrieve the data.

0

No no no - I want to do it so I don't have to Call the data every time and I want to have an easy way using the above script that I can call from anywhere to SetAsync if you get what I mean? That means I only have the one datastore request for the whole server lifetime! ;)