How to check if player is holding ANY tool

I’ve read multiple post about checking tool but it doesn’t show how to check if player is holding ANY tool.
Could someone please help me?

(if holding any item true then return true else return false)

3 Likes
local HoldingTool = (Player.Character:FindFirstChildWhichIsA("Tool") ~= nil and true) or false

if HoldingTool then 
print("holding tool")
end
3 Likes

didnt work :smiling_face_with_tear: player is supposed to be game.Players.LocalPlayer right?

1 Like

if you want to check if the localplayer is holding it then yes (must be a localscript)

2 Likes

You can use childAdded on the character, use a for i,v loop on it and see if its a tool

1 Like

Else, if you dont need the game to constantly check if a player just equipped, you can do what czo said

On czo’s script, I would just remove the true and nil and false cause if im right, findfirstchild means checking if it exists

op said that they want it to return true of false, findfirstchild returns either the instance that it found or nil

Oh i apologize then, i dint saw that

1 Like

Well wouldn’t it be better to remove it either way and add return true else return nil?

local Player = game.Players.LocalPlayer

Player.Character.ChildAdded:Connect(function()
	for i, v in pairs(Player.Character:GetChildren()) do
		if v:IsA("Tool") then
			print("Player is holding a tool.")
		end
	end
end)

Try this. Put it in a LocalScript inside of StarterGui (or wherever you want the script to be parented.) Hope this helps!

1 Like

how would i go on to check if it’s not holding it tho? I tried doing elseif not v:IsA(“Tool”) but it didn’t work as for some reason the value didnt change.

Anyways I already found a solution. Thanks for everyone who commented in this post and helped me find a solution :heart:

1 Like

My bad dont listen to me lol idk whats happening to me

local Player = game.Players.LocalPlayer

Player.Character.ChildAdded:Connect(function()
	for i, v in pairs(Player.Character:GetChildren()) do
		if v:IsA("Tool") then
			print("Player is holding a tool.")
		elseif not v:IsA("Tool") then
			Player:Kick("You do not have a tool. Goodbye") --Change this to whatever you want to happen.
		end
	end
end)

This should work. It did for me!

local player = game.Players.LocalPlayer
return player.Character:FindFirstChildOfClass("Tool") and true or false

maybe combine

GetDescants()

or

GetChildren()

with

for _,tool

and use the

if Tool.Equipped then

thing idk if it works tho

local function isHoldingTool(player)
	local ch = player.Character or player.CharacterAdded:Wait()
	if ch:FindFirstChildWhichIsA("Tool") then
		return true
	end
	return false
end)

isHoldingTool(playerObject) --replace playerObject with the Player
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.