Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How would you find the current equipped tool?

I need to get to whatever tool the player has equipped currently. I know that when a player equips a tool, it goes to the character. So how would I get to that tool?

I have thought of trying to find the first child that is a tool. I don't know how to do this yet and I don't know if it is very efficient as it would break when another tool is added.

3 comments

0

You should post your attempt. It helps not only us, but yourself too. It's okay to ask for help. If you have a question on how to do something and you have an attempt, post it. .

0

I haven't attempted it, I have no clue on what functions I would use to do this.

0

Are you looking for a list of tools the player has equipped? If that's the case then you'd want to start by creating a simple while loop combined with in pairs that constantly searches for tools inside the player's character, then you want to use table.insert to add the tool into a table. Then finally using a for loop to print the contents of the table.

1 answer

Easiest way it to find out what tool equipped is to use the event called Activated. Assuming this is in a localscript and you want all tools to be checked:

local plr = game.Players.LocalPlayer
if #plr.Backpack:GetChildren() > 0 then -- Checks if there is any tools.
	for i, v in pairs(plr.Backpack:GetChildren()) do -- Iterate through the tools.
		if v:IsA("Tool") then -- Checks if the child is a tool.
			v.Activated:connect(function() -- Checks if it's equipped.
				-- code here
			end)
		end
	end
end

or if you want to find out just for one tool:

local plr = game.Players.LocalPlayer
if #plr.Backpack:GetChildren() > 0 then -- Checks if there is any tool.
	plr.Backpack["toolnamehere"].Activated:connect(function()
		-- code here
	end)
end

This discussion is preserved as it was. New answers, comments, and votes are closed.