Should I Handle Tool Detection on the Client or Server?

Hi everyone,

I’m working on a system to detect Tools and I’m wondering whether it’s better to handle it on the Client or Server.

I’ve created a module called Tool_Detection, which:

  • Detects when a player equips, activates, or unequips a tool.
  • Works on both the Server and the Client (with minor modifications).

Here’s the module code:

local Tool_Detection = {}
Tool_Detection.__index = Tool_Detection

function Tool_Detection.new(player: Player)
	local self = setmetatable({}, Tool_Detection)

	self.Player = player
	self.Character = player.Character or player.CharacterAdded:Wait()
	self.Tool = nil
	self.ToolEquipped = false
	self.Connections = {}  


	self.Player.CharacterAdded:Connect(function(character)
		self.Character = character
		self:ToolDetect()
	end)

	self:ToolDetect()

	return self
end

function Tool_Detection:ClearToolMemory()
	if self.Tool then
		self.Tool = nil
	end
	
	self.ToolEquipped = false

	for name, connection in pairs(self.Connections) do
		if name ~= "ChildAdded"  then
			connection:Disconnect()
			self.Connections[name] = nil
		end
	end
end

function Tool_Detection:ToolDetect()
	if self.Connections["ChildAdded"] then
		self.Connections["ChildAdded"]:Disconnect()
		self.Connections["ChildAdded"] = nil
	end

	self.Connections["ChildAdded"] = self.Character.ChildAdded:Connect(function(child: Tool)
		self:SetUpTool(child)
	end)
end


function Tool_Detection:SetUpTool(tool: Tool)
	if tool:IsA("Tool") and tool:FindFirstChild("Handle") then
		self:ClearToolMemory()
		
		self.Tool = tool

		self.Connections["Equipped"] = self.Tool.Equipped:Connect(function()
			self:Equipped()
		end)

		self.Connections["Activated"] = self.Tool.Activated:Connect(function()
			self:Activated()
		end)

		self.Connections["Unequipped"] = self.Tool.Unequipped:Connect(function()
			self:UnEquipped()
		end)
	end
end

function Tool_Detection:Equipped()
	self.ToolEquipped = true
	print(self.Tool.Name .. " equipped.")
end

function Tool_Detection:Activated()
	if not self.ToolEquipped then
		return
	end
	print("Activated")
end

function Tool_Detection:UnEquipped()
	self:ClearToolMemory()
end


function Tool_Detection.Init(modules, remotes)
	
	game:GetService("Players").PlayerAdded:Connect(function(player)
		Tool_Detection.new(player)
	end)
end


return Tool_Detection

Since this system only detects tools and their activation, would it be better to keep it on the Client or Server?

I’d really appreciate any advice or suggestions!

I would do it depending on how its meant to function

But most likely you want to detect tools on the server as im pretty sure it doesnt replicate to the server on the client.This will allow you verify and have more safety options than letting the client have the power to abuse it.

Yes, I also considered putting it on the server since I have important tool data stored there, and accessing it without using remotes is easier.

I’m going to try a different approach using OOP and inheritance before deciding whether to stick with this first module.

Server sided everything is the best choice

Thats cool using OOP is a great way to manage different Tools and code in mechanics for them.

Yeah, that’s why I love OOP! It makes everything so much easier to manage and expand.