Tool.Activated firing on equipping tool (Custom hotbar)

I made a custom hotbar for my game, and whenever you equip a tool by tapping the UI on mobile, it fires Tool.Activated. Here’s my code:

local players = game:GetService("Players");
local replicatedStorage = game:GetService("ReplicatedStorage");
local stun = replicatedStorage.Stun;

local localPlayer = players.LocalPlayer;
local gun = script.Parent;

gun.Activated:Connect(function()
	print("activated");
end);

I also tried equipping the tool on the server by firing a remote event but the result is the same. This is what I do for equipping the tool:

self._humanoid:EquipTool(tool) -- // Equip the tool

I’d appreciate help! Thanks for reading.

Is the tool equipped? I don’t seem to be understanding the problem

It’s probably because when you tap the screen, it equips the tool but then registers the tap as an activation. Try creating a variable named equipped, set it to true or false when the tool is equipped/unequipped and then check if equipped == true in the activated function. And you could even try adding a delay, so it sets equipped to true 0.5 second after equipping

1 Like

Could you explain to me what the problem of this user seems to be? you seem to have understood, but I have not

When the player equips the tool by tapping the UI on the mobile, it fires the activated event along with the equipped event. I’m currently trying what @WoTrox has said.

1 Like

I would just not rely on the Activated event, and whenever the tool equips I will create a temporary connection (until unequipped) for whenever there is a Tap/Click (use ContextActionService).
Make sure you don’t equip the tool whenever the tool button is held, but rather clicked, because as previously stated it may register the Activated event on release.