Tool saving system NOT WORKING

Hey! So I need a tools saving system, So I got one

local dss = game:GetService("DataStoreService")
local toolsDS = dss:GetDataStore("ToolsData")

local toolsFolder = game.ServerStorage.Tools

game.Players.PlayerAdded:Connect(function(plr)

	local toolsSaved = toolsDS:GetAsync(plr.UserId .. "-tools") or {}

	for i, toolSaved in pairs(toolsSaved) do

		if toolsFolder:FindFirstChild(toolSaved) then 

			toolsFolder[toolSaved]:Clone().Parent = plr.Backpack
			toolsFolder[toolSaved]:Clone().Parent = plr.StarterGear 
		end
	end

	plr.CharacterRemoving:Connect(function(char)

		char.Humanoid:UnequipTools()
	end)
end)


game.Players.PlayerRemoving:Connect(function(plr)

	local toolsOwned = {}

	for i, toolInBackpack in pairs(plr.Backpack:GetChildren()) do

		table.insert(toolsOwned, toolInBackpack.Name)
	end

	local success, errormsg = pcall(function()

		toolsDS:SetAsync(plr.UserId .. "-tools", toolsOwned)
	end)
	if errormsg then warn(errormsg) end
end)

But the problem is that when the tool is inside the character (the player is holding the tool) and I leave the game, Once I rejoin it does not save

1 Like

Are you testing it in game or in studio? Data stores don’t save in studio and to fix that you would use game:BindToClose in a server script

I noticed it only gets the backpack for the saving portion.

You will also need to search the character if they are holding the tool as the tool is parented to the character.

You can use plr.Character:FindFirstChildOfClass(“Tool”) to find the tool they are holding and save it.

well in this part

plr.CharacterRemoving:Connect(function(char)

		char.Humanoid:UnequipTools()
	end)

it should unequip the tools and place it in the backpack right?

I tried in both roblox, And studio they both didnt work

I don’t think so. Maybe this is the problem then?

It says here what it does

The unequipped Tool will be parented to the Backpack of the Player associated with the Humanoid. If no Tool is equipped, this function will do nothing.

I read it and it said it puts into the backpack, I dont really understand?

If no Tool is equipped, this function will do nothing.

Try using this

local plr = game.Players.LocalPlayer
local char = plr.Character
for _, obj in pairs(char:GetChildren()) do

if obj:IsA("Tool") then

	obj.Parent = plr.Backpack


	end)

end

1 Like

is there some code missing there?

Well it doesn’t work because when you hold a tool in roblox the tool becomes a child of your character, so instead get the player’s character and get an array of its children. Use an if statement to check if its in the player’s character.

Just where you define the player and character other than that no, I am a little new to the forum and still have not figured out code boxes as they are very confusing, I edited it to show it correctly, You just need to put this in a local script in starterplayerscripts

I actually played around with that code for a little bit and it seemed it worked, Thanks!

for _, obj in pairs(char:GetChildren()) do

if obj:IsA("Tool") then

	obj.Parent = plr.Backpack


	end)
end

@DyzuOfficial this is his code.

not you copying and pasting my exact code :blush::blush: i feel so flattered

I made the textbox for you lol. I should’ve quoted mb.

You could do the same as said above like:

local tool = char:FindFirstChildWhichIsA("Tool")
if tool then
    tool.Parent = plr.Backpack
end

The solution has already been marked, Why did you boost the thread just to repost my code?

I don’t see why I cannot post a more efficient code than what was posted above… Unless you have some problems yourself, then that’s on you. Technically, I’m not reposting your code :slight_smile:

It literally is my exact code as I provided what you could do to implement it and a easy way to implement it easily but less efficent for the game, Honestly I don’t understand why you are reposting people’s code just to farm likes, if you want to farm likes or shares or whatever just go to tiktok or instagram, The devforum is supposted to be used to help people, not just farm likes so you can get fancy badges. :-1: