Right now, I have a semi-working saving system using InstanceStore.
It uses a data folder from ServerScriptService to load the data values.
- The problem is that whenever we update the game, and add more values to this folder, players that have already played the game and have the data folder stored will not have the new values we want to add from said update.
The main saving script located in ServerScriptService:
game:GetService("Players").PlayerAdded:Connect(function(plr)
local ds = game:GetService("DataStoreService")
local datastore = ds:GetDataStore("PlayerData_Testing") -- its named like that for studio testing
local converter = require(game:GetService("ServerScriptService"):FindFirstChild("Converter"))
-- i moved all of this down because of some problems i forgot
--local dataFolder = game:GetService("ServerScriptService"):FindFirstChild("Data"):Clone()
--dataFolder.Name = "Data"
--dataFolder.Parent = plr
local plrData
local suc, err = pcall(function()
plrData = datastore:GetAsync("Key_" .. plr.UserId)
end)
if err then warn("An error occurred while trying to load data for " .. plr.Name .. " | Error: " ..tostring(err)) end
if suc then
if plrData then
print(plrData)
local savedDataFolder = converter:ConvertToInstance(plrData)
savedDataFolder.Parent = plr
else
local dataFolder = game:GetService("ServerScriptService"):FindFirstChild("Data"):Clone()
dataFolder.Name = "Data"
dataFolder.Parent = plr
datastore:SetAsync("Key_" .. plr.UserId, converter:ConvertToSaveable(plr:FindFirstChild("Data"), true))
end
end
end)
game:GetService("Players").PlayerRemoving:Connect(function(plr)
local ds = game:GetService("DataStoreService")
local datastore = ds:GetDataStore("PlayerData_Testing")
local converter = require(game:GetService("ServerScriptService"):FindFirstChild("Converter"))
local suc, err = pcall(function()
datastore:SetAsync("Key_" .. plr.UserId, converter:ConvertToSaveable(plr:FindFirstChild("Data"), true))
end)
if err then warn("An error occurred while trying to save data for " .. plr.Name .. " | Error: " ..tostring(err)) end
end)
If someone could help me fix or implement a system that adds new values that don’t exist in the players data then that would be great. Thanks!