hi everyone, i am making a game a need data stores to syc between places in the game. I dont know how to do this but my current script is
local currencyName = "Coins"
local DataStore = game:GetService("DataStoreService"):GetDataStore("TestDataStore")
game.Players.PlayerAdded:Connect(function(player)
local folder = Instance.new("Folder")
folder.Name = "leaderstats"
folder.Parent = player
local currency = Instance.new("IntValue")
currency.Name = currencyName
currency.Parent = folder
local ID = currencyName.."-"..player.UserId
local savedData = nil
pcall(function()
savedData = DataStore:GetAsync(ID)
end)
if savedData ~= nil then
currency.Value = savedData
print("Data loaded")
else
-- New player
print("New player to the game")
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local ID = currencyName.."-"..player.UserId
DataStore:UpdateAsync(ID,player.leaderstats[currencyName].Value)
end)
game:BindToClose(function()
-- When game is ready to shutdown
for i, player in pairs(game.Players:GetPlayers()) do
if player then
player:Kick("This game is shutting down")
end
end
wait(5)
end)
It depends really, if your place is in the same universe (game) then you can easily get the data on every place instance as reflected in the datastore documentation. If they aren’t in the same universe however then you’d have to use http service to a third party to handle transfers but then it would be questionable as to why you don’t have the same place and then a single hub.