To put it simply I need help with the logic behind UpdateAsync, I’ve read a few posts as well as official documentations but I can’t seem to find a satisfactory explanation to my inquiry.
I’m going to take a small example from my game because using my whole code will get too messy and confusing for the reader to understand, so:
print("Starting function")
GlobalItemDataHandler:UpdateAsync("Data", function(OldData)
--Some code in here to remove player's data from the Market.
print("Running function")
return OldData
end)
--[[
Expected behaviour:
All print functions only occur once.
Actual behaviour:
"Starting function" prints once whilst "Running function" repeats continuously.
]]--
I have this simple UpdateAsync function, all it does is it removes an item a player listed from our in-game Market.
However, “Starting function” prints once, as expected. “Running function” on the other hand proceeds to print out multiple times in the console.
From what I’ve read I believe it’s something to do with multiple server instances interacting with eachother? Is there anyway I can counteract this so the code in the UpdateAsync only runs once per person per server?
you could compile the servers edits, and apply them all at once.
another thing I can think of is adding another global data store variable called currently accessing, which stores an identifier based on the server’s id or the player’s username, so other servers are able to tell a single server is accessing the data.
another idea is to create a base server that handles all updates and receives information from the other servers, you could implement this using Cross-Server Messaging | Documentation - Roblox Creator Hub it would also need code to transfer the base server upon closure.
these were just possible solutions, as the issue could still be present, but by “compiling the servers edits”, I mean sending the data from each player to a single script which then takes that data and calls the function applying every edit within the same call to the data store.