Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

What Did I Do Wrong In This ToolSaver Script? That Should Save Tools

Asked by 3 years ago

so my tool save is not working and idk why script is here

local dss = game:GetService("DataStoreService")
local toolsDS = dss:GetDataStore("ToolsData3")

local toolsFolder = game.ReplicatedStorage:WaitForChild('Tools')

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)

so the tools dont save AND it does not give me any error thanks for reading!!

1 answer

Log in to vote
0
Answered by 3 years ago

Have you tried doing this?

  • tell me if this works since i'm not good with DataStoreService!
local unpackTools = {}
local toolsSaved = toolsDS:GetAsync(plr.UserId .. "-tools")

table.insert(unpackTools, toolsSaved)

    for i, toolSaved in pairs(unpackTools) do

        if toolsFolder:FindFirstChild(toolSaved) then

            toolsFolder[toolSaved]:Clone().Parent = plr.Backpack
            toolsFolder[toolSaved]:Clone().Parent = plr.StarterGear
      end
end
0
Ok tnx i just woke up so let me try later Rgboffical_yt 40 — 3y
0
You mean try the whole script you gave? Rgboffical_yt 40 — 3y
0
Like i mean should i replace my Whole Scriot with that?or replace with a certain line? Rgboffical_yt 40 — 3y
Ad

Answer this question