Hello,
So it isn’t working as intended, as when I try to use this method instead of the method of using the PlayerDataTemplate, it simply doesn’t get my saved data within the datastore. I will reply this with the entire data template code, and I am curious as to why this isn’t fetching what is required for the datastore? AS it will only work as intended when that PlayerDataTemplate is generated.
Thank you!
local DSS = game:GetService("DataStoreService")
local RepStorage = game:GetService("ReplicatedStorage")
local CrossfireDataStore = DSS:GetDataStore("v1.2_AchaeologistStorage")
local PlayerDataTemplate = {
--// Prior Values \\--
["Cosmetic"] = {"StringValue", "None"},
["Uniform"] = {"StringValue", "None"},
--//\\ Number Values //\\--
["Coins"] = {"NumberValue", 15}, -- Base money, awarded for gameplay
["XP"] = {"NumberValue", 0}, -- Determines level
["XP_Floor"] = {"NumberValue", 75}, -- Determines level floor
["Level"] = {"NumberValue", 1}, -- lvl
["Serial"] = {"NumberValue", 1}, -- Bone Adjustment Serial, adds every time you generate a new aged/enchanted bone
--//\\ Stackable Items //\\--
--// Bones
["Bones"] = {"NumberValue", 0},
["Large Bones"] = {"NumberValue", 0},
["Dinosaur Bones"] = {"NumberValue", 0},
["Wing Bones"] = {"NumberValue", 0},
["Fish Bones Small"] = {"NumberValue", 0},
["Fish Bones Large"] = {"NumberValue", 0},
["Tail Bones"] = {"NumberValue", 0},
["Ribcage"] = {"NumberValue", 0},
["Shark Skulls"] = {"NumberValue", 0}
--// Rare Bones
["TRex Skull"] = {"BoolValue", false},-- [Rarity = Prehistoric], BONE REQUIREMENTS{}
["Pterodactyl Skull"] = {"BoolValue", false},-- [Rarity = Prehistoric], BONE REQUIREMENTS{}
--Fish Small
["Small Fish - Bass"] = {"BoolValue", false},
["Small Fish - Trout"] = {"BoolValue", false},
["Small Fish - Pike"] = {"BoolValue", false},
["Small Fish - Carp"] = {"BoolValue", false},
["Small Fish - Perch"] = {"BoolValue", false},
["Small Fish - Pickerel"] = {"BoolValue", false},
--Fish Large
["Large Fish - Catfish"] = {"BoolValue", false},
["Large Fish - Nile Perch"] = {"BoolValue", false},
["Large Fish - Salmon"] = {"BoolValue", false},
["Large Fish - Sturgeon"] = {"BoolValue", false},
--Fish Dino
["Greatwhite Shark"] = {"BoolValue", false},
["Bull Shark"] = {"BoolValue", false},
["Tiger Shark"] = {"BoolValue", false},
["Mako Shark"] = {"BoolValue", false},
["Megladon"] = {"BoolValue", false},
["Mosasaurs"] = {"BoolValue", false},
["Dunkleosteus"] = {"BoolValue", false},
-----------------------------------------------------------------
--//\\ First time in game assets //\\--
["FirstTime"] = {"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 = "PlrStats"
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("NumberValue") or object:IsA("StringValue") then
object.Value = GetSave[object.Name]
end
end
--[[
--// getsave method, didnt work with above commented out/not
for key,value in pairs(GetSave) do
if typeof(value) == "BoolValue" then
local newValue = Instance.new("BoolValue")
newValue.Name = key
newValue.Value = value
newValue.Parent = Bools
elseif typeof(value) == "NumberValue" then
local newValue = Instance.new("NumberValue")
newValue.Name = key
newValue.Value = value
newValue.Parent = stats
elseif typeof(value) == "StringValue" then
local newValue = Instance.new("StringValue")
newValue.Name = key
newValue.Value = value
newValue.Parent = stats
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 PlrStats = player.PlrStats
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(PlrStats: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(5)
end)