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

Why is my weapon saving script not saving new weapons?

Asked by 4 years ago

THIS SCRIPT ALWAYS WORKS BUT ITS ONLY LOADING WEAPONS WHEN U JOIN AND NOT SAVING THEM WHEN U LEAVE SO IF U GET A NEW WEAPON IS DOESNT SAVE PLS HELP ME

local ds = game:GetService("DataStoreService"):GetDataStore("ToolSave")
game.Players.PlayerAdded:Connect(function(plr)
    local key = "id-"..plr.userId
    pcall(function()
        local tools = ds:GetAsync(key)
        if tools then
            for i,v in pairs(tools) do
                local tool = game.ServerStorage.Tools:FindFirstChild(v)                 
                if tool then
                    tool:Clone().Parent = plr:WaitForChild("Backpack")
                    tool:Clone().Parent = plr:WaitForChild("StarterGear")

                end
            end
        end
    end)
end)
game.Players.PlayerRemoving:Connect(function(plr)
    local key = "id-"..plr.userId
    pcall(function()
        local toolsToSave = {}
        for i,v in pairs(plr.Backpack:GetChildren()) do
            if v then
                table.insert(toolsToSave,v.Name)
            end
        end
        for fuck, you in pairs(plr.Character:GetChildren()) do
            if you.ClassName == "Tool" then
            table.insert(toolsToSave,you.Name)  
            end
        end
    ds:SetAsync(key,toolsToSave)
 end)
end)

0
Why does line 27 have the F word on it? Dovydas1118 1495 — 4y
0
You definitely should not be using curse words in your code. Roblox goes through code, and that can get you banned and or terminated. DarkDanny04 407 — 4y
0
oh i didnt know ill remove it sorry coolmanHDMI 72 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

Here's what u wanted, i didn't test it tho

local Players = game:GetService("Players")

game:BindToClose(function()
    for i,v in pairs(Players:GetPlayers()) do
    local key = "id-"..v.userId
    pcall(function()
        local toolsToSave = {}
        for l,k in pairs(v.Backpack:GetChildren()) do
            if v then
                table.insert(toolsToSave,k.Name)
            end
        end
        for s, d in pairs(v.Character:GetChildren()) do
            if you.ClassName == "Tool" then
            table.insert(toolsToSave,d.Name)  
            end
          end
         ds:SetAsync(key,toolsToSave)
       end
   end)
end)
Ad

Answer this question