Tool saving script won't work

I finished it @zhenjie2003Alt. There wasn’t one so I added it.

Well it should work now. Try it and if it works please mark me as solution.

1 Like

It doesn’t work @zhenjie2003Alt but it got rid of the error.

Then it’s something else with your code. I can’t help any further right now so either you’re gonna have to figure it out yourself or have someone else help sorry.

1 Like

Are you still having problems or is it fixed?

1 Like

Could you mention or check what exactly is inside ToolData?

1 Like

He puts the name of every tool on the player inside the ToolData

1 Like

Still the same error sadly, I might give up

Which error? thought the ToolFolder one was fixed

1 Like

Why did you separate this 2 functions?

1 Like

It was a typo. @Sarturex857 whoops my bad.

No errors by error I meant it doesn’t work.

When you load the data from the datastore to the player backpack also clone it and put it into toolFolder

1 Like

So, I made kind of the same system but with bools, I’ve made some changes in my script, and now it can save tools.

local Savings = game:GetService('DataStoreService'):GetDataStore('Tools')
local RS = game:GetService('ReplicatedStorage')

local tools = RS.Tools -- you can change this, type the ubication of the folder that contains your tools

local data

local tabb = {}

game.Players.PlayerAdded:Connect(function(plr)
	--give data
	local s, e = pcall(function()
		data = Savings:GetAsync(plr.UserId)

		for i, v in pairs(tools:GetChildren()) do
			if data ~= nil then
				local cloned_tool = tools:FindFirstChild(data[v.Name]):Clone()
				cloned_tool.Parent = plr.Backpack
			end	
		end
	end)

	if not s then
		print(e)
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	--save data
	local tools = plr.Backpack
	plr.Character.Humanoid:UnequipTools()

	local s, e = pcall(function()
		for i, v in pairs(tools:GetChildren()) do
			tabb[v.Name] = v.Name
		end
		Savings:SetAsync(plr.UserId, tabb)
	end)
	if not s then
		warn(e)
	end
end)
2 Likes

Replace this line with

ToolData = SaveData:GetAsync(Player.UserId) or {}

I also don’t see that the data is being saved. If you are planning to save this tool table, make sure to JSONEncode it before saving and JSONDecode it before passing it into the for loop

1 Like

Thanks everyone Ill try it all out Ill respond if it doesnt work thanks for the support. @TheBrainy06 it didn’t work and @Sarturex857 it gives me this error ServerScriptService.InventorySaver:31: attempt to index nil with ‘Humanoid’ for this line of code plr.Character.Humanoid:UnequipTools()

When I tested my script before, it worked, but I don’t know what problem you have, what parts of the script did you modified?

1 Like

I have modified Nothing (I know the folder must be name related I took care of that) the only thing that I did was replicate the tools folder twice one for rep storage and one for ss

Try replacing plr.Character.Humanoid:UnequipTools() with plr.Character:WaitForChild(“Humanoid”):UnequipTools() or something, I don’t know.

This gives me more errors I don’t think that was it.