Hey y’all, been running into a problem as of recent. Now sure entirely as to why.
So the long and the short of it, whenever I want to say “Update” my game, and add new things into the system, I obviously add these items into my datastore. So, as I do this, I playtest to see if the store will work with the item, BUT, what happens is the item adds, but it resets all the other stats. I don’t change the key when I update this store, the “132800913”, so that’s not the problem.
I am completely stumped as to what this may be, here’s my code;
local DSS = game:GetService("DataStoreService")
local RepStorage = game:GetService("ReplicatedStorage")
local CrossfireDataStore = DSS:GetDataStore("132800913")
local PlayerDataTemplate = {
--// Number Values \\--
["Kills"] = {"NumberValue", 0},
["XP"] = {"NumberValue", 0},
["Coins"] = {"NumberValue", 0},
["Wallets"] = {"NumberValue", 0},
--// Gun Skins \\--
--Soon
--// Guns \\-
["SCAR"] = {"BoolValue", false},
["M4A1"] = {"BoolValue", false},
["MP5"] = {"BoolValue", false},
["Revolver"] = {"BoolValue", false},
["AK-47"] = {"BoolValue", false},
["M249"] = {"BoolValue", false},
["USP"] = {"BoolValue", true},
["SPAS-12"] = {"BoolValue", false},
["UZI"] = {"BoolValue", false},
["RPK"] = {"BoolValue", false},
["SKS"] = {"BoolValue", false},
["AN-94"] = {"BoolValue", false},
["C7A2"] = {"BoolValue", false},
["9mm"] = {"BoolValue", false},
["M16"] = {"BoolValue", false},
--// Achievements \\--
["5000_Kills"] = {"BoolValue", false},
["500_Kills"] = {"BoolValue", false},
["1000_Kills"] = {"BoolValue", false},
--// Extras \\--
["Hints"] = {"BoolValue", false},
["Russian_Made"] = {"BoolValue", false},
["Canadian_Made"] = {"BoolValue", false},
--// Crosshairs \\--
["Green"] = {"BoolValue", false},
--// Confetti \\--
["Ghost"] = {"BoolValue", false},
["Pumpkin"] = {"BoolValue", false},
["Dew"] = {"BoolValue", false},
["VIP"] = {"BoolValue", false},
["Phantomsoft"] = {"BoolValue", false}
}
game.Players.PlayerAdded:Connect(function(player)
local playerKey = "Player-ID:"..player.UserId
local Bools = Instance.new("Folder", player)
Bools.Name = "Bools"
local stats = Instance.new("Folder",player)
stats.Name = "stats"
for name, object in pairs(PlayerDataTemplate) do
local newValue = Instance.new(object[1])
newValue.Name = name
newValue.Value = object[2]
if object[1] == "NumberValue" or object[1] == "StringValue" then
newValue.Parent = stats
else
newValue.Parent = Bools
end
end
local GetSave;
local success, message = pcall(function()
GetSave = CrossfireDataStore:GetAsync(playerKey)
end)
if success then
if GetSave then
for _, object in ipairs(Bools:GetChildren()) do
if object:IsA("BoolValue") then
print(object.Name, GetSave[object.Name])
object.Value = GetSave[object.Name]
end
end
for _, object in ipairs(stats:GetChildren()) do
if object:IsA("StringValue") or object:IsA("NumberValue") then
object.Value = GetSave[object.Name]
end
end
print("Data loaded for "..player.Name)
else
print("Test")
end
else
print("Problem loading data!")
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local playerKey = "Player-ID:"..player.UserId
local Bools = player.Bools
local stats = player.stats
local tableToSave = {};
for _, object in ipairs(Bools:GetChildren()) do
if object:IsA("BoolValue") then
tableToSave[object.Name] = object.Value
end
end
for _, object in ipairs(stats:GetChildren()) do
if object:IsA("StringValue") or object:IsA("NumberValue") then
tableToSave[object.Name] = object.Value
end
end
local success, message = pcall(function()
CrossfireDataStore:SetAsync(playerKey, tableToSave)
end)
if success then
if message then
print(message)
end
print("saved success for "..player.Name)
end
end)
game:BindToClose(function()
wait(20)
end)