My Tool Handler

Hello, but I need feedback and suggestions to my Tool Handler. The Tool Handler detects when you equip something and calls the module, so I don’t have to repeat Local Scripts, Scripts and Remote Events.

Here is the code:

local Player = game:GetService("Players").LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local ToolsFolder = ReplicatedStorage:WaitForChild("Tools")

local function CheckTool(Object : Instance)
	if Object:IsA("Tool") then
		return true
	end
end

local function ReturnModule(ObjectName : string)
	local ToolModule = ToolsFolder:FindFirstChild(ObjectName)
	
	if ToolModule then
		ToolModule = require(ToolsFolder:FindFirstChild(ObjectName))
		return ToolModule
	end
end

Player.CharacterAdded:Connect(function(Character : Model)
	Character.ChildAdded:Connect(function(Child : Instance)
		local Tool : Tool = Child
		if not CheckTool(Tool) then return end
		
		local Module : ModuleScript = ReturnModule(Tool.Name)
		
		Tool.Activated:Connect(function()
			-- Tool Logic
		end)
		
		Tool.Equipped:Connect(function()
			-- Tool Logic
		end)
		
		Tool.Unequipped:Connect(function()
			-- Tool Logic
		end)
	end)
end)

I found one thing I need to use meta tables and check if the player is alive.

dont forget to disconnect the tool.activated and tool.equipped functions when the player leaves or dies

Yea, that’s a good idea.

What are the pros to disconnect? Can’t it prevent memory leaks?

yes, if u don’t disconnect connections like that, it just eats up memory

Do you have an idea on how I could implement this into my code?

local LastConnection = nil

And add the connections and disconnect it when a new tool is added or the player dies?