Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Tool saving script only loaded tools once? [FIXED]

So, I followed a yt tutorial on how to make a tool saving script. The first time I tried loading the tools it worked normally, but the 2nd time I played the game the script broke. Does anybody know how to fix this? Here's the script:

local dss = game:GetService("DataStoreService")
local toolsDS = dss:GetDataStore("ToolsData")
 
local toolsFolder = game.ServerStorage.ToolsFolder
 
game.Players.PlayerAdded:Connect(function(plr)
    
    local toolsSaved = toolsDS:GetAsync(plr.UserId .. "-tools") or {}
    
    for i, toolSaved in pairs(toolsSaved) do
            
        if toolsFolder:FindFirstChild(toolSaved) then 
            
            toolsFolder[toolSaved]:Clone().Parent = plr.Backpack
			toolsFolder[toolSaved]:Clone().Parent = plr.StarterGear 
			
        end
    end
    
    plr.CharacterRemoving:Connect(function(char)
        
        char.Humanoid:UnequipTools()
    end)
end)
 
 
game.Players.PlayerRemoving:Connect(function(plr)
    
    local toolsOwned = {}
    
    for i, toolInBackpack in pairs(plr.Backpack:GetChildren()) do
        
        table.insert(toolsOwned, toolInBackpack.Name)
    end
    
    local success, errormsg = pcall(function()
        
        toolsDS:SetAsync(plr.UserId .. "-tools", toolsOwned)
    end)
    if errormsg then warn(errormsg) end
end)

game:BindToClose(function()
	local players = game.Players:GetPlayers()
	for i = 1, #players do
		local plr = players[i]
		
		local toolsOwned = {}
    
    for i, toolInBackpack in pairs(plr.Backpack:GetChildren()) do
        
        table.insert(toolsOwned, toolInBackpack.Name)
    end
    
    local success, errormsg = pcall(function()
        
        toolsDS:SetAsync(plr.UserId .. "-tools", toolsOwned)
    end)
    if errormsg then warn(errormsg) end
	
	end
	end)

Also, I would like to address some common questions you may ask:

  1. API Services are enabled.
  2. I tested it both in studio and in the real game.
  3. There are no errors in the output.
  4. I can tell the problem is with loading the tools because when I stop the game in the output it says "DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = 178628425-tools", meaning that it saved properly.

So if anybody could help I would really appreciate it!

4 comments

0

UPDATE: If you have 2 tools in your inventory, 1 of them will save

0

Update 2: Its keeping only 1 item saved, not any others though

0

It randomly started working.

0

...And it stopped working again. oof

1 answer

So, it turns out if you clone the tool from workspace, it doesn't work. If you clone the tool from the tools folder, the autosave feature works.

This discussion is preserved as it was. New answers, comments, and votes are closed.