Tool is apparently nil

Awhile back I made a tool saving system and its been working fine for a while. However, when I went on vacation, and recently came back, I’ve come to realize that its not working. Basically, you equip a tool, click a slot on the GUI, and it should save to a folder inside the player. However, for some reason, when you equip the tool and click a slot, the tool is nil. This is from what I’ve seen the only issue in the entire system. I might also note that the game features the players character switching a lot.

Client code:

`--//Services
local PLAYERS = game:GetService("Players")
local RS = game:GetService("ReplicatedStorage")

--//Variables
local player = PLAYERS.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local inventory = player:WaitForChild("Inventory")
local buttons = script.Parent
local inventory_event = RS:WaitForChild("SAVING_EVENTS").ITEM_INVENTORY
local back_tool_event = RS:WaitForChild("SAVING_EVENTS").GIVE_BACK_TOOL

for i, button: TextButton in buttons:GetChildren() do 
	if not button:IsA("TextButton") then
		continue
	end

	if inventory:GetChildren()[i] then
		button.Text = inventory:GetChildren()[i].Name
	end

	button.MouseButton1Down:Connect(function()
		print("Fired")
		local tool_in_character = character:FindFirstChildOfClass("Tool")
		
		
		if (tool_in_character) and (tool_in_character.CanBeDropped == true) then
			print("Tool found in character:", tool_in_character.Name)
			local tool = character:FindFirstChildOfClass("Tool")

			inventory_event:FireServer(tool)

			button.Text = tool.Name

		elseif (inventory:FindFirstChild(button.Text)) then
			local tool = inventory:FindFirstChild(button.Text)
			
			back_tool_event:FireServer(button.Text)
			button.Text = ""
		end
	end)
end`

Any help is appreciated :cowboy_hat_face: