I tell you that my doubt is the operation of the globaldatastore, I need to save values within the 2 games that I am doing so that the player has his inventory saved in the games. the games are in the same place.
This is the script I use to save the data right now and I created another extension that should reproduce the value in the other place but it doesn’t work. I would like someone to teach me the reason why it does not work. Thank you.
local DataStore = game:GetService("DataStoreService")
local Data1 = DataStore:GetDataStore("Data1")
game.Players.PlayerAdded:Connect(function(player)
--test
local Test = Instance.new("Folder", player)
Test.Name = "Test"
local Test1 = Instance.new("IntValue", Test)
Test1.Name = "Test1"
local DataA1
local ok, errorf = pcall(function()
DataA1 = Data1:GetAsync(player.UserId)
end)
if ok then
print("Data")
Test1.Value = DataA1 or 0
else
print("Error")
error(errorf)
end
while true do
wait(10)
player.Test.Test1.Value += 1
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local ok, errorf = pcall(function()
Data1:SetAsync(player.UserId, player.Test.Test1.Value)
end)
if ok then
print("DataB")
else
print("ErrorB")
error(errorf)
end
end)
local ds = game:GetService("DataStoreService"):GetGlobalDataStore()
game.Players.PlayerAdded:Connect(function(plr)
wait()
local plrKey = "id_"..plr.UserId
local save1 = plr.Test.Test1
local Saved = ds:GetAsync(plrKey)
if Saved then
save1.Value = Saved[1]
else
local NumberForSaving = {save1.Value}
ds:GetAsync(plrKey, NumberForSaving)
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
ds:SetAsync("id_"..plr.UserId, {plr.Test.Test1.Value})
end)