Search code examples
luaroblox

Roblox Studio - Why is my DataStore not updating in real time across servers?


I've created a colored grid that the player can change, and every few seconds, I set a DataStore to the state of the grid. It saves fine, but it does not update in other servers, even though I have code for it to update. It only updates when you leave the server. Anyone know why this is?

I tried sending the data of the grid. I expected it to sync across all servers. Instead it saved, but only updated on one server.


Solution

  • According to the DataStores documentation, GlobalDataStore:GetAsync will cache the result of the previous fetch for 4 seconds.

    Keys are cached locally for 4 seconds after the first read. A GlobalDataStore:GetAsync() call within these 4 seconds returns a value from the cache. Modifications to the key by GlobalDataStore:SetAsync() or GlobalDataStore:UpdateAsync() apply to the cache immediately and restart the 4 second timer.

    So if you want your data to update across servers, you need to space out how often you read from the store. Try fetching the data once every ten seconds or more.