All stats save perfectly, except for MaxStamina. If any of the stats are changed, MaxStamina doesn’t save. If only MaxStamina is changed, MaxStamina saves.
Really weird problem, I hope someone that reads this has a clue on how to solve it.
local Defaults = {
Strength = 0,
Agility = 0,
Durability = 0,
Toughness = 0,
Special = 0,
MaxStamina = 100
}
local function OnPlayerAdded(Player)
local StatDS = DataStore2("Stats", Player)
local function StatsUpdate(newValues)
local Stats = Player:WaitForChild("StatFolder")
local StatArray = {"Strength", "Agility", "Durability", "Toughness", "Special", "MaxStamina"}
local function Check(thing)
for i, v in pairs(StatArray) do
if v == thing then
return true
end
end
end
for i, v in pairs(newValues) do
if Check(tostring(i)) then
Stats[tostring(i)].Value = v
end
end
end
StatsUpdate(StatDS:GetTable(Defaults))
StatDS:OnUpdate(StatsUpdate)
end
game.Players.PlayerAdded:Connect(OnPlayerAdded)
I believe this is the only relevant part of the script but I can post the other parts too if needed.
Okay, I tested some more and it seems it only saves any data that has changed, and old data that didn’t change gets defaulted. Sorry for not checking thoroughly before
Okay, I tested some more and it seems it only saves any data that has changed, and old data that didn’t change gets defaulted. Sorry for not checking thoroughly before. This is what you said.
But it’s still a problem though. I gave myself 15 strength and it saved, I went back and gave myself 15 durability to have 15 str and dura, and only the durability saved. How can I make it also save the past strength?