Saving Tools Datastore

Before anything:

  • I do not know how datastores work, I’ve tried to document myself from the official Roblox datastore documentation site but I barely understood anything.
  • I know there’s a lot of posts about tool saving and a lot of Youtube videos about it, but for some reason, every tool saving datastore method that I’ve tried either doesn’t work at all or works a couple of times then it breaks. I have tried so many tool saving methods but all of them did not work and did not have what I require for my game.
    I just need some help with this.

What I’d like to achieve:

  • A datastore that saves the players Backpack upon leaving/resetting
  • Does not break after a couple of tests

What have I tried:
I’ve tried a couple of datastore scripts but this is the latest one that I’ve tried

local toolFolder = game:GetService("ServerStorage"):FindFirstChild("SavedToolss") 
local dataStoreSer = game:GetService("DataStoreService")
local saveData = dataStoreSer:GetDataStore("ToolSaverTest")

game.Players.PlayerAdded:Connect(function(Player)
	local toolData = saveData:GetAsync(Player.UserId)
	
	local backpack = Player:WaitForChild("Backpack")
	local StarterG = Player:WaitForChild("StarterGear")
	
	if toolData ~= nil then
		for i, v in pairs(toolData) do
			if toolFolder:FindFirstChild(v) and backpack:FindFirstChild(v) == nil and StarterG:FindFirstChild(v) == nil then
				toolFolder[v]:Clone().Parent = backpack
				toolFolder[v]:Clone().Parent = StarterG
			end
		end
	end
	
	Player.CharacterRemoving:Connect(function(Character)
		Character:WaitForChild("Humanoid"):UnequipTools()
	end)
end)

game.Players.PlayerRemoving:Connect(function(Player)
	local toolTable = {}
	
	for i,v in pairs(Player.Backpack:GetChildren()) do
		table.insert(toolTable, v.Name)
	end
	if toolTable ~= nil then
		saveData:SetAsync(Player.UserId, toolTable)
	end
end)

This one only saves the tools whenever the player leaves, not when the player resets.

I just need some help with this because every post and Youtube video has been of no help.

2 Likes

The best way to go about this, is to use an established DataStore module like ProfileService. Save your player data with ProfileService! (DataStore Module)
This has a tutorial in it to set it up. From there you should save the Name of every tool into that datastore on death (Humanoid.Died:Connect()) and leaving (Players.PlayerRemoving:Connect()). When joining (Players.PlayerAdded:Connect()) and after dying/resetting (Player.CharacterAdded:Connect()) you can get the weapons again and give them to the player’s backpack.

1 Like

I’m trying to understand it with the tutorials provided and other helpful stuff but I can’t seem to understand how to save the tools yet.

I don’t think you can insert tools in StarterPack/Gears

Let’s take your code:

for i,v in pairs(Player.Backpack:GetChildren()) do
	table.insert(toolTable, v.Name)
end

You should load the data before that, as well as directly saving into that one;

local data = YourDataStore:GetDataFromThisDataStore(Player)
for i,v in pairs(Player.Backpack:GetChildren()) do
	data.SavedTools[i] = v.Name
end

Now you have the names of the tools at the position they previously were in the backback.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.