Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
seikkatsu 110
5 years ago

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

1 answer

Log in to vote
2
Answered by
royaltoe 5144 Moderation Voter Community Moderator
5 years ago

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)
0
ill try your script in a second seikkatsu 110 — 5y
0
alright. also, please indent the return on line 6. i tried but for some reason it ended up like that in the formatting royaltoe 5144 — 5y
0
so i have to delete it? i don't know the word "indent" sorry. my first language isnt enlish seikkatsu 110 — 5y
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. royaltoe 5144 — 5y
View all comments (14 more)
0
but the script doesn't work seikkatsu 110 — 5y
0
i get an error on line 4 saying that the character is a nil value seikkatsu 110 — 5y
0
is it in a normal script or local script? royaltoe 5144 — 5y
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 royaltoe 5144 — 5y
0
it's a local script seikkatsu 110 — 5y
0
replace line one with this code: royaltoe 5144 — 5y
0
player = game.Players.LocalPlayer local char = player.Character or player.CharactedAdded:wait() royaltoe 5144 — 5y
0
hmm still doesn't work seikkatsu 110 — 5y
0
i have had the local script parented to the tool was that ok? seikkatsu 110 — 5y
0
i'll check it out later today after class im starting a class rn royaltoe 5144 — 5y
0
thats fine royaltoe 5144 — 5y
0
:p thanks for all the help. it was me beeing stupid this whole time :/ sorry for wasting this much of your time seikkatsu 110 — 5y
0
you didn't waste my time. don't worry about it. royaltoe 5144 — 5y
0
i'm glad you got it working royaltoe 5144 — 5y
Ad

Answer this question