Hey, so i'm saving all of the players tools to a datastore and loading them up every time they join the game or reset. For some reason even after the tools have saved before they died, it will still load up the tool set that they had when they first joined the game. I can't quite work out why it's doing this as the script is looking fine to me.
Ill post the Save and Load functions i've got here, if you can spot anything out of the ordinary that would be great! Thanks, Cuv
Here is the Save function;
function Save(PlayerIns)
if PlayerIns then
if PlayerIns:findFirstChild("Backpack") then
local SP = {}
if SaveBackpackPrefer == true then
SP = PlayerIns.Backpack:GetChildren()
else
SP = PlayerIns.StarterGear:GetChildren()
end
local Data = DataStore:GetSaveData(PlayerIns)
local Tools = {}
for i = 1, #SP do
table.insert(Tools,#Tools+1,SP[i].Name)
end
if SaveBackpackPrefer == true then
local SP2 = PlayerIns.Character:GetChildren()
for i = 1, #SP2 do
if SP2[i].className == "Tool" then
table.insert(Tools,#Tools+1,SP2[i].Name)
end
end
end
Data:Set("ToolSaves",Tools)
if PrintTables then
print("["..PlayerIns.Name.."]Saving... "..assert(LoadLibrary("RbxUtility")).EncodeJSON(Tools))
end
end
end
end
And here is the load function;
function Load(PlayerIns)
local Data = DataStore:GetSaveData(PlayerIns)
local Tools = (Data:Get("ToolSaves") or {})
if PrintTables then
print("["..PlayerIns.Name.."]Loading... "..assert(LoadLibrary("RbxUtility")).EncodeJSON(Tools))
end
for i = 1, #Tools do
if game.ServerStorage:findFirstChild(Tools[i]) then
local Tool2 = game:GetService(Container):findFirstChild(Tools[i]):clone()
Tool2.Parent = PlayerIns.Backpack
end
end
end
