Help With Tool Saving Datastore

Hello i followed a YouTube video on how to make a tool saving DataStore and it doesn’t work, i don’t know if its because i have a cash DataStore already. If you could help me that would be great.

Tool Saving

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
		ds:SetAsync(key, toolstosave)
	end)
end)
1 Like

What about it doesn’t work?
Are there any errors?
Have you tried using prints to debug?

We need more context than “it doesn’t work” so then we can help you.

Cool tip: Remove the pcalls temporarily to see if the code inside the pcalls is erroring or you can define it’s success and response:

local success, response = pcall(function()
    --code
end)

if not success then
    error(response)
end

The tool saving doesn’t work and doesn’t save the tools, no there are not any errors and i think that’s the pcalls fault, i will remove the pcalls and see what happens

i didn’t get any errors and it doesn’t save any tools

What type of Script is it? (It should be a Script)
And where? (Preferably ServerScriptService, Workspace is fine though)
Also, are you certain that the Tool is inside game.ServerStorage.Tools?

It is a script and in serverscript service and i put all my tools into serverstorage, also quick update i started getting dupes and removing the pcalls saved 1 item…?

dupes

ok it stared saving items but is duping others that i got rid of