I recently released a game called Slayer’s Legacy. I never had issues when we were testing the game with our friends but we didn’t really have any issues with datastore in testing. When we released the game we started to have so many reports because of data lose.
This is how i save the data:
local players = game:GetService("Players")
local DataStore2 = require(game:GetService("ServerScriptService"):WaitForChild("MainModule"))
local mainKey = "Data-7"
DataStore2.Combine(mainKey, "Stats")
local function setDataTable()
local userData = {
["BreathLvl"] = 1,
["FaceId"] = 0,
["IsDemon"] = false,
["JP"] = 57.5,
["WS"] = 17,
["Karma"] = 0,
["EXP"] = 0,
["Style"] = "Nothing",
["HasSkill1"] = false,
["HasSkill2"] = false,
["HasSkill3"] = false,
["Rank"] = 0,
["EquippedKatana"] = "Nothing",
["HandleColor"] = "Nothing",
["Handle2Color"] = "Nothing",
["BladeColor"] = "Nothing",
["FinalSelection"] = false,
["Money"] = 0
}
return userData
end
players.PlayerAdded:Connect(function(plr)
local status = plr:WaitForChild("Status")
local stats = plr:WaitForChild("Stats")
local mood = plr:WaitForChild("Mood")
local blocking = status:WaitForChild("Block")
local stunned = status:WaitForChild("Stunned")
local breathing = status:WaitForChild("Breath")
local IsEquipped = status:WaitForChild("IsEquipped")
local died = status:WaitForChild("Died")
local EquippedKatana = stats:WaitForChild("EquippedKatana")
local breathlvl = stats:WaitForChild("BreathLvl")
local faceId = stats:WaitForChild("FaceId")
local handleColor = stats:WaitForChild("HandleColor")
local handle2Color = stats:WaitForChild("Handle2Color")
local bladeColor = stats:WaitForChild("BladeColor")
local isDemon = stats:WaitForChild("IsDemon")
local style = stats:WaitForChild("Style")
local hasSkill1 = stats:WaitForChild("HasSkill1")
local hasSkill2 = stats:WaitForChild("HasSkill2")
local hasSkill3 = stats:WaitForChild("HasSkill3")
local exp = stats:WaitForChild("EXP")
local karma = stats:WaitForChild("Karma")
local rank = stats:WaitForChild("Rank")
local finalSelection = stats:WaitForChild("FinalSelection")
local money = stats:WaitForChild("Money")
local userData
local dataTable
local isDataLoaded = false
spawn(function()
userData = DataStore2("Stats", plr)
dataTable = userData:GetTable(setDataTable())
for i,v in pairs(stats:GetChildren()) do
v.Value = dataTable[v.Name]
v.Changed:Connect(function()
dataTable[v.Name] = v.Value
userData:Set(dataTable)
if v.Name == "Rank" then
updateRank(plr)
updateClothes(plr, hasCustomClothes)
end
end)
end
if faceId.Value == 0 then
faceId.Value = faceTable[math.random(1, #faceTable)]
end
if handleColor.Value == "Nothing" then
handleColor.Value = tostring(BrickColor.Random())
end
if handle2Color.Value == "Nothing" then
handle2Color.Value = tostring(BrickColor.Random())
end
if bladeColor.Value == "Nothing" then
bladeColor.Value = tostring(BrickColor.Random())
end
isDataLoaded = true
updateRank(plr)
end)
end)