My tool data store isn't replicating the tools

I’m trying to get a save room type saving system in my game. I almost have the tool data store working, but I can’t figure out why it isn’t replicating the tools. I put printing messages to try to fix this, but I have no idea what the issue is. It either isn’t saving the tools at all, or is not loading them. Here is the code(the problem is at the AreaSave:LoadTools or AreaSave:SaveTools). The way it is suppose to work(which it did at one point) is to save toolids to the data store then match them with the correct tool. Any help would be appreciated. Thanks

local GameDataModule = {}

local DSS = game:GetService("DataStoreService")

local AreaSave = {}

function AreaSave:SetPosition(player,room)

     local area = DSS:GetDataStore("Save Room")

     local key = "Player_" .. player.UserId

     local rooms = {}

     rooms.x = room.X

     rooms.y = room.Y

     rooms.z = room.Z

     local success,errormessage = pcall(function()

          area:SetAsync(key,rooms)

     end)

     if success then

          print("Successfully Saved Position")

     else

          warn(errormessage)

     end

end

function AreaSave:GetPosition(player)

     local key = "Player_" .. player.UserId

     local area = DSS:GetDataStore("Save Room")

     local data

     local success,errormessage = pcall(function()

          data = area:GetAsync(key)

     end)

     if success then

          print("Successfully loaded position")

          local coordinate = Vector3.new(data.x,data.y,data.z)

          return coordinate

     end

end

function AreaSave:SaveTools(player)

     local backpack = player.Backpack

     local save = DSS:GetDataStore("Tools")

     local tools = {}

     local pack = backpack:GetChildren()

     local bag = player.Character:GetChildren()

     for i = 1, #pack do

          local id = pack[i]:FindFirstChild("ToolId")

          if id then

               tools[i] = pack[i].ToolId.Value

          end

     end

     for i = 1, #bag do

          if bag[i]:IsA("Tool") then

               local id = bag[i]:FindFirstChild("ToolId")

               if id then

                    tools[i] = bag[i].ToolId.Value

               end

          end

     end

     local key = "Player_" .. player.UserId

     local Success,errormessage = pcall(function()

          save:SetAsync(key,tools)

     end)

     if Success then

          print("Saved Tools")

     else

          warn(errormessage)

     end

end

function AreaSave:LoadTools(player)

     wait(1)

     local save = DSS:GetDataStore("Tools")

     local key = "Player_" .. player.UserId

     local ids

     local success,errormessage = pcall(function()

          ids = save:GetAsync(key)

     end)

     if success then

          print("Loading tools")

          for _, id in pairs(ids) do

               local tool = script.Parent.ToolId:FindFirstChild(tostring(id))

               if tool then

                    local o = tool.Value:Clone()

                    o.Parent = player.Backpack

                    print("Loaded tool " .. tostring(id))
                    -- It doesn't say this part meaning that no tools were loaded --
               end

          end

          print("Finished loading")
          -- it still says that it finished loading with no errors --
     end

end

function GameDataModule:LoadSave(player)

     local room = AreaSave:GetPosition(player)

     player.Character:MoveTo(room)

     AreaSave:LoadTools(player)

end

function GameDataModule:SaveRoom(player,position)

     AreaSave:SetPosition(player,position)

     AreaSave:SaveTools(player)

end

return GameDataModule

Here are the instances.
Screenshot 2022-01-17 105327

1 Like

Sorry guys, I noticed I named the “Toolid” wrong, so that’s why it wasn’t replicating.