How do I check if a tool is equipped?
Im not talking about the Equipped event where you can run some code if someone equipps a tool. I want to know how to check anytime if a tool is equipped or isn
t
Thanks for Reading!
you check wether the tool is in the Character or the PLayer’s backPACK
local equipped = false
local tool = script.Parent
tool.Equipped:Connect(function()
equipped = true
end)
tool.Unequipped:Connect(function()
equipped = false
end)
-- if you need to check this outside of the one script, you can do this if check or use _G or modules (modules are definitely more recommended than _G especially if you're checking this on the client):
if plr.Character:FindFirstChild("ToolName") and plr.Character["ToolName"]:IsA("Tool") then
print("equipped")
end
He said without the equipped event btw. He wants to know a different way
I know, I provided an example with & without needing .Equipped, after the comment is without needing the events.
For anyone who wants this, there is a better way of doing the second option
Instead of saying:
if plr.Character:FindFirstChild("ToolName") and plr.Character["ToolName"]:IsA("Tool") then
print("equipped")
end
you can just do:
if plr.Character:FindFirstChildOfClass("Tool") then
print("equipped")
end
Actually, I think the first option is better because if you have more then one tool it will just count another tool that you are not trying to check if it is equipped.
edit: yes, I know that this is 6 months later.
You can’t have more than one tool equipped at a time tho ( dam it’s been 6 months?? )
And if you were asking if OP wanted to check for a specific tool, it says in the title “How do I check if a tool is equipped?”
oh. Right. I have no idea what I was thinking. and yeah, 6 months lol
You can actually have 2 tools equipped at the same time, but it can only be fired by a script.
This really helped thanks. I really wanted this script.
also its 2023 now so its been 3 years
Thanks a lot, and happy July, 2024!
If you want to check if any tool is equipped, you can use this piece of code in a local script and voila.
--// Services
local Players = game:GetService("Players")
--// Variables
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
--// Functions
function ChildAdded()
if character:FindFirstChildOfClass("Tool") then
print("equipped")
end
end
--// Connections
character.ChildAdded:Connect(ChildAdded)