So for one of my projects, I'm trying to make a game where every server is sharing the same resource pool. The main problem is that I can't find an effective or efficient way to change the value to an exact amount for every server.
E.G: There are currently 10 materials.
A player from server 1 deposits 3 materials.
There are now 13 materials in the 'resource pool' on every single server.
Now a player from server 2 takes out 4 materials.
There are now 9 materials on every server.
The main issue is that the players would be scattered across multiple servers, changing the value every time they deposit/withdraw the resource. I don't have any ideas on how I would constantly keep the value shared between every server - especially if multiple people are withdrawing and depositing at the same time.
What happened when I tested the game with multiple servers and players constantly withdrawing/depositing was that the server would be overloaded with requests and it would mess the values up between servers because they were constantly
As for any code samples -
local DataStore = game:GetService("DataStoreService"):GetDataStore("Armory") game.Players.PlayerAdded:connect(function(player) local key = "play" DataStore:UpdateAsync(key, function(oldValue) local newValue = oldValue or 0 newValue = newValue + 50 game.Workspace.OutpostOmeet.OutpostData.Armory.Points.Value = newValue return newValue end) end)
All this really does is adds a value to the datastore - then makes the armory points become the new value. I think the main problem with it is that if something else was being changed on another server - it wouldn't try and detect that, so it would be really clunky. Sending a request every X seconds would also feel pretty clunky.