Local:
local remote = game:GetService("ReplicatedStorage"):WaitForChild("Remotes"):WaitForChild("Save")
local ld = game.Players.LocalPlayer:WaitForChild("leaderstats")
local folder = game.Players.LocalPlayer:WaitForChild("Data")
while true do
wait(5) -- TIME FOR SAVE
local saveDataTable = {}
table.insert(saveDataTable, 1, ld.Wins.Value)
table.insert(saveDataTable, 2, ld.Power.Value)
table.insert(saveDataTable, 3, folder.PlusPower.Value)
table.insert(saveDataTable, 4, ld.Mass.Value)
table.insert(saveDataTable, 6, folder.PlusMass.Value)
table.insert(saveDataTable, 7, ld.Rebirth.Value)
remote:FireServer(saveDataTable)
--print("Autosaved ".. game.Players.LocalPlayer.Name.. "'s Data")
end
Server:
local DataStore = game:GetService("DataStoreService"):GetDataStore("Saves")
local saveRemote = game:GetService("ReplicatedStorage"):WaitForChild("Remotes"):WaitForChild("Save")
game.Players.PlayerAdded:Connect(function(player)
local ld = Instance.new("Folder", player)
ld.Name = "leaderstats"
local folder = Instance.new("Folder", player)
folder.Name = "Data"
local tools = Instance.new("Folder", player)
tools.Name = "Tools"
local wins = Instance.new("IntValue", ld)
wins.Name = "Wins"
local power = Instance.new("IntValue", ld)
power.Name = "Power"
local plusPower = Instance.new("IntValue", folder)
plusPower.Name = "PlusPower"
local mass = Instance.new("IntValue", ld)
mass.Name = "Mass"
local plusMass = Instance.new("IntValue", folder)
plusMass.Name = "PlusMass"
local rebirth = Instance.new("IntValue", ld)
rebirth.Name = "Rebirth"
local success, errormag = pcall(function()
local getData = DataStore:GetAsync(player.UserId)
for i, v in pairs(getData) do
if i == 1 then
wins.Value = getData[i]
elseif i == 2 then
power.Value = getData[i]
elseif i == 3 then
plusPower.Value = getData[i]
elseif i == 4 then
mass.Value = getData[i]
elseif i == 5 then
plusMass.Value = getData[i]
elseif i == 6 then
rebirth.Value = getData[i]
end
end
end)
if success then
--print("Successfully loaded ".. player.Name.. "'s data!")
elseif not success then
-- FIRST TIME JOINING --
wins.Value = 0
power.Value = 0
plusPower.Value = 1
mass.Value = 0
plusMass.Value = 1
rebirth.Value = 0
local powerTool1 = game:GetService("ReplicatedStorage"):WaitForChild("Tools").Dumbbell1
powerTool1.Parent = player.Backpack
local massTool1 = game:GetService("ReplicatedStorage"):WaitForChild("Tools").Mass1
massTool1.Parent = player.Backpack
game:GetService("ReplicatedStorage"):WaitForChild("Settings").currentTool.Value = powerTool1.Name
--error("Something went wrong while loading the data of ".. player.Name.. ": ".. errormag)
end
end)
saveRemote.OnServerEvent:Connect(function(player, val)
DataStore:SetAsync(player.UserId, val)
--print("Successfully saved ".. player.Name.. "'s data!")
end)
So I have this system working, that is, when I quit the game, everything is saved. BUT!!! Here when I decided to add Rebirth, then when I exit and a new entry into the game it was not saved although the rest of the data is still saved, the error is not written, so the question. Why it is not saved?
P.S. initially rebirth I have on 0, I make it 1, and leave the game. At a new entry, all is saved but rebirths are equal to 0.