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

Why is my weapon saving script not saving new weapons?

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)

3 comments

0

Why does line 27 have the F word on it?

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.

0

oh i didnt know ill remove it sorry

1 answer

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)

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