How to create a global table variable between servers

I want to store a global table variable and when updated, all the different servers receive that value. I tried using DataStore but it doesn’t seem to let me save it as a Dictionary
image

Before saving table in question, try using HttpService:JSONEncode(), when you want to read saved data, transform it back to table using HttpService:JSONDecode()

Just set up a normal data store, and use MessagingService to communicate the change to other servers

It should be possible. Like @Rynappel said you would have a datastore and use MessagingService to update all servers. Something like this will work though it’s quite rough but you should get an idea of how it’ll work.

local DataStoreService = game:GetService("DataStoreService")
local MessagingService = game:GetService("MessagingService")

local KEY: string = "DataStoreKeyHere"
local SCOPE: string = "Values"

local DataStore = DataStoreService:GetDataStore(KEY)

local Values = {}

--@@ Update DataStore
local function Update(Key, Value)
   DataStore:UpdateAsync(SCOPE, function(oldData)
      oldData[Key] = Value
      return oldData
   end

  MessagingService:PublishAsync("UpdateData")
end

--@@ Get Data
local function Sync()
  	local Success, Result = pcall(function()
		return DataStore:GetAsync(SCOPE)
	end)

	if Success and Result then
		Values = Result
        print("Data is synced with server")
	end
end

--@@ Subscribe to topic
MessagingService:SubscribeTopic("UpdateData", function()
   Sync()
end)
1 Like