i did a module datastore script that worked perfectly, i tried making it soo i could add new values without breaking the datastore completely, because my game will always be updated with new content everyday, and with my old datastore scripts i had to wipe data every single time i updated, and now it ins’t saving, soo what i need is help to fix the scripts and make soo i can add new values whenever i want without having to data wipe, 100% of the roblox games dont need to data wipe when adding new content to the datastore, but when i search how to do that, i either cant find anything or people tell me to use datastore 2 (which is super messy), also someone said using datastore 2 doesn’t changes anything soo yeah
problems: broken save script, need to wipe data everytime i add new values
module script:
local dsinfo = {
folder_name = "DATA";
ds_name = "WDYF_TEST0333";
key = "WDYF-";
data = {
coins = {"IntValue", 0};
};
};
return dsinfo
server script (inside the module, however i dont think thats the problem)
local PS = game:GetService("Players")
local RUN = game:GetService("RunService")
local DSS = game:GetService("DataStoreService")
local DSM = require(script.Parent)
local DS = DSS:GetDataStore(DSM.ds_name)
function save(p)
local key = DSM.key .. p.userId
local tosave = {}
local folder = p:FindFirstChild(DSM.folder_name)
if not folder then return end
for _, stat in pairs(folder:GetChildren()) do
tosave[stat.Name] = stat.Value
end
local s, e = pcall(function()
DS:SetAsync(key, tosave)
end)
if not s then
warn(p.Name .. " Data Error: " .. e)
end
end
PS.PlayerRemoving:Connect(save)
PS.PlayerAdded:Connect(function(p)
local key = DSM.key .. p.userId
local currentsave = DS:GetAsync(key)
local folder = Instance.new("Folder",p)
folder.Name = DSM.folder_name
for name, stat in pairs(DSM.data) do
local newval = Instance.new(stat[1])
newval.Name = name
newval.Value = stat[2]
newval.Parent = folder
end
if currentsave then -- LOAD
for l, stat in pairs(folder:GetChildren()) do
if currentsave[stat.Name] then
stat.Value = currentsave[stat.Name]
else
local missing = DSM.data[stat.Name]
stat.Value = missing
currentsave[stat.Name] = missing
end
end
save(p)
for l,s in pairs(currentsave) do
print(l, s)
end
else
save(p)
end
end)
-- # studio bugfix # -- (not the problem btw)
game:BindToClose(function()
wait(5)
end)