Tools doesn't save on death but saves on rejoin

hello developers! i have this tool saving system taken from a youtube video and it does work. the problem is that the tool does not save when you reset but it saves when you rejoin having tool being held/in the backpack. i’ve tried taking the tooldata part in the player added function into the character removing function but it didn’t work. i’ve also searched for issues for this bug and found this. i have tried to use the solution and changed the code for it to make it properly work, but it didn’t work. any help appreciated! :innocent:

(this is my first post so i’m expecting it to be bad)

local toolFolder = game:GetService("ServerStorage"):FindFirstChild("tools"):FindFirstChild("shop")
local dataStoreService = game:GetService("DataStoreService")
local saveData = dataStoreService:GetDataStore("SaveData")

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

game:GetService("Players").PlayerRemoving:Connect(function(player)
	local toolTable
	
	for i, v in pairs(player.Backpack:GetChildren()) do
		if not toolTable then
			toolTable = {}
		end
		
		table.insert(toolTable, v.Name)
	end
	
	if toolTable then
		saveData:SetAsync(player.UserId, toolTable)
	end
end)
1 Like

Place the tool under both Backpack and StarterGear in the player instance, when you clone the tool in to StarterGear, once character respawns the tool gets automatically added to player backpack again.

Edit: Sorry, I noticed you are doing that, I’ll take a look again and see if I can help you any further.

2 Likes

From my understanding, you are saving and loading player tools when they rejoin your game, the tool should be re-added back to the player’s backpack if you also place them under StarterGear. I don’t see any issues with it.

Run the game, check your player instance, and see if there are any tools inside StarterGear.

2 Likes

thank you so much! i found a fix to it.

apparently, you need to copy and paste the cloning tool code and instead of putting it into the backpack, you put it in the startergear. if you also want to remove the tool, you have to delete the tool from startergear.

thank you so much! i couldn’t find a fix for this for months :sob:

1 Like

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