Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

Tool saving script only loaded tools once? [FIXED]

Asked by 12 days ago
Edited 10 days ago

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!

0
UPDATE: If you have 2 tools in your inventory, 1 of them will save Jac_00b 6 — 12d
0
Update 2: Its keeping only 1 item saved, not any others though Jac_00b 6 — 12d
0
It randomly started working. Jac_00b 6 — 11d
0
...And it stopped working again. oof Jac_00b 6 — 11d

1 answer

Log in to vote
0
Answered by 10 days ago

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.

Ad

Answer this question