Its simple:
local DataStoreService = game:GetService("DataStoreService")
local dataStore = DataStoreService:GetDataStore("SharedValueStore")
pcall(function()
dataStore:SetAsync("SharedValue", 123)
end)
--every server have "SharedValue"
1 Like
the variable will never change… like in game? right?
1 Like
Yes. Use SetAsync(key, value) (or better, UpdateAsync) and GetAsync(key)
Until you change the value using the method, the value will remain the same. In fact, it’s just a storage between servers
1 Like
TY very much ((((((((((((((((((((((((((:
oh and if it is updated in one server will it update in all server instantly
and is there anyway to access the variable from another script
Of course, there is a delay, but it comes down to the data transfer rate of the roblox servers. Well, that is, updating data on other servers should happen, if not instantly, then exactly within 5 seconds.
1 Like
code1:
local DataStoreService = game:GetService("DataStoreService")
local secretData = DataStoreService:GetDataStore("Secret")
local SECRET_KEY = "Secret1"
local secretValue = 12
--use pcall to set/get value. Im dont doing it here because Im stupid (lazy)
secretData:SetAsync(SECRET_KEY, secretValue)
code2:
local DataStoreService = game:GetService("DataStoreService")
local secretData = DataStoreService:GetDataStore("Secret")
local SECRET_KEY = "Secret1"
task.wait(3) -- wait until data get updated
local secret = secretData:GetAsync(SECRET_KEY)
print(secret) -- should print 12
1 Like