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

How to check if a player has a tool equipped in their hand?

Pretty self explanatory. I would like to check if a player equipped a tool thanks in advance for the help

1 answer

✓ Accepted answer

When you equip a tool, it ends up inside the character. When you want to check if a tool is being equipped, call this function:

local character = game.Players.LocalPlayer.Character

function toolEquipped(character)
	for _, child in pairs(character:GetChildren()) do 
       		if child:IsA("Tool") then 
			return true 
	        end
	end
	return false
end

if(toolEquipped(character))then
	print("There is a tool equipped")
else
	print("there is not a tool equipped")
end

If you want t know if a certain tool is equipped, then check the Tool's equipped property:

Tool.Equipped:Connect(function(mouse)
    print("Tool was equipped")
end)

18 comments

0

ill try your script in a second

0

alright. also, please indent the return on line 6. i tried but for some reason it ended up like that in the formatting

0

so i have to delete it? i don't know the word "indent" sorry. my first language isnt enlish

0

no, and that's okay. i just mean press the 'Tab' key on your keyboard on line 6. Doesn't do anything, just makes it easier to read.

0

but the script doesn't work

0

i get an error on line 4 saying that the character is a nil value

0

is it in a normal script or local script?

0

the code above needs to be a local script. if you want to do it in a normal script, you're going to need to know what player you want beforehand

0

it's a local script

0

replace line one with this code:

0

player = game.Players.LocalPlayer local char = player.Character or player.CharactedAdded:wait()

0

hmm still doesn't work

0

i have had the local script parented to the tool was that ok?

0

i'll check it out later today after class im starting a class rn

0

thats fine

0

:p thanks for all the help. it was me beeing stupid this whole time :/ sorry for wasting this much of your time

0

you didn't waste my time. don't worry about it.

0

i'm glad you got it working

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