How do I check whenever a tool (No matter which) has been equipped

  1. What do you want to achieve?

So, I want to make a script that whenever a player equips a tool (No matter what tool it is) it will find which tool and it will print the name and also the player who equipped it.

  1. What is the issue?

I am not sure how I would do it, I thought of using a for loop to go through the Character, but that doesn’t do it as it doesn’t have an event that I am aware of using yet, so nothing actually happens with the for loop.

  1. What solutions have you tried so far?

Yes, I have tried looking on ScriptingHelpers and also on the forum, however, I can’t seem to find anything with my answer. This is the for loop that I have used yet nothing happens as it isn’t accompanied by an event.

local character = game.Players.LocalPlayer.Character

for i,v in pairs(character:GetChildren()) do
	if v:IsA("Tool") then
		print(v.Name)
	end
end

Be sure to ask any questions if my topic doesn’t make any sense, I will be active on here for a while.

4 Likes

I can think of two ways off the top of my head.

  1. Go through the Player’s backpack and connect an Equipped event to each tool and just run a function when the tool has been equipped.
  2. Use the ChildAdded event to check if a tool was added to the Player’s character.
12 Likes

Just figured this out as you had typed it, I didn’t think of doing childAdded and checking if it was a tool. Just for future reference if someone is having the same problem, this is the way that I managed to do it.

Code:

character.ChildAdded:Connect(function(tool)
	if tool:IsA("Tool") then
		print(tool.Name) -- you don't have to print the tool's name
	end
end)
19 Likes

you can also do a tool.Equipped

5 Likes