Inventory / Tool save not working

Hello, I’m working on a toolsave, for future work, but it doesn’t seem to work. I also get an error in the output that says “argument 2 missing or nil” - Line 100. I will provide the script below.

1 Like
local ss = game:GetService("ServerStorage")
local dss = game:GetService("DataStoreService")
local datastore = dss:GetDataStore("ToolData")
local library = ss:WaitForChild("Tools")

local dir = {}

local function edit(player, list)
	dir[player.Name] = list
end

local function setup(player, list)
	for i = 1, #list do
		local tool = library:FindFirsrChild(list[i])
		if tool then
			local clone = tool:Clone()
			clone.Parent = player.Backpack
		else 
			print(list[i] .. " not found!")
		end
	end
end

game.Players.PlayerAdded:Connect(function(player)
	
	local ready = false
	
	player.CharacterAdded:Connect(function(char)
		
		local backpack = player.Backpack
		local data = nil
		
		if ready == false then
			ready = true
			
			data = datastore:GetAsync(player.UserId)
			
			if data then
				setup(player, data)
				edit(player, data)
			end
		end
		char.Humanoid.Died:Connect(function()
			char.Humanoid:UnequipTools()
			
			local old = player.StarterGear:GetChildren()
			for i = 1, #old do
				old[i]:Destroy()
				 
			local new = player.Backpack:GetChildren()
			for i = 1, #old do
				new[i].Parent = player.StarterGear
			end
		end
		
		local count = 0
		local function adjust()
			
		if char.Humanoid.Healt > 0 then
				
		local list = {}
				
		local equipped = char:FindFirstChildOfClass("Tool")
		if equipped then
			table.insert(list, equipped.Name)			
		end			
					
					local tools = backpack:GetChildren()
					for i = 1, #tools do
						table.insert(list, tools[i].Name)
					end
					
					if count ~= #list then
						edit(player, list)
						count = #list
					end
					
			end
			end
			
			backpack.ChildAdded:Connect(adjust)
			backpack.ChildRemoved:Connect(adjust)
			
			char.ChildAdded:Connect(function(child)
				if child.ClassName == "Tool" then
					adjust()
				end
			end)
			
			char.ChildRemoved:Connect(function(child)
				if child.ClassName == "Tool" then
					adjust()
				end
			end)
		end)
	end)
end)

game.Players.PlayerRemoving:Connect(function(player)
 	datastore:SetAsync(player.UserId, dir[player.Name]) -- line 100
	dir[player.Name] = nil
end)

game:BindToClose(function()
	wait(100)
end)
1 Like

you can gat my model

1 Like

Thanks, i will look into the script. I didn’t know roblox changed how the Datastores worked. Thx!

1 Like

The only issue I currently see is that you’re typing FindFirsrChild instead of FindFirstChild.

Oh yea, that didn’t help either. Last time i tried to use datastore was back in 2017-18.