My tools (guns) won't save (Updated)

I want to be able to join my game and have my guns stay as they were, if they were in my backpack then they are in my backpack, if they were equipped then they are equipped.

Problem is that my guns won’t save.

Video of problem: 2023-11-16 12-51-20.mp4 - Google Drive

here is the script:

local DataStoreService = game:GetService("DataStoreService")
local ToolDataStore = DataStoreService:GetDataStore("ToolDataStore")

local backpackTools = {}
local characterTools = {}

game.Players.PlayerAdded:Connect(function(player)
	-- Load saved tools
	local savedTools = ToolDataStore:GetAsync(tostring(player.UserId))
	if savedTools then
		for _, toolName in ipairs(savedTools.backpackTools) do
			local tool = game.ServerStorage.Guns:FindFirstChild(toolName):Clone()
			tool.Parent = player.Backpack
		end
		for _, toolName in ipairs(savedTools.characterTools) do
			local tool = game.ServerStorage.Guns:FindFirstChild(toolName):Clone()
			tool.Parent = player.Character
		end
	end
end)
game.Players.PlayerRemoving:Connect(function(player)
	for _, tool in pairs(player.Backpack:GetChildren()) do
		table.insert(backpackTools, tool.Name)
	end
	for _, tool in pairs(player.Character:GetChildren()) do
		if tool:IsA("Tool") then
			table.insert(characterTools, tool.Name)
		end
	end
	ToolDataStore:SetAsync(tostring(player.UserId), {backpackTools = backpackTools, characterTools = characterTools})
end)



The error code: (but I can’t figure out why it won’t still work when I changed it)

  12:51:59.079  ServerScriptService.ToolSave:26: attempt to index nil with 'GetChildren'  -  Server

Looks like you forgot to add the “player” parameter

why you put PlayerRemoving event in player joined function? it will fire for every player when any player left. better to do like this:

game.Players.PlayerAdded:Connect(function(player) ... end)
game.Players.PlayerRemoving:Connect(function(player) ... end)

(you have this:)

game.Players.PlayerAdded:Connect(function(player)
  game.Players.PlayerRemoving:Connect(function() ... end) -- if any player left, this will fire for ALL players
end)

I have updated my script but it still doesn’t work.