I can't find if a player has a tool in the character

Hi guys, currently i’m working in a project witch it needs to check i a player has any type of a item inside the character.

i tried so far some scripts but no one is currently working:

local player = game:GetService("Players").LocalPlayer
	
local character = player.Character
--

if character:FindFirstChildOfClass("Tool") then
	print("has a item")
elseif not character:FindFirstChildOfClass("Tool") then
	print("hasn't a item")
end

Can anyone help me?

thanks

NIK_

1 Like

You need to make does player has tool in backpack.

local backpack = player.Backpack

change “if character:FindFirstChildOfClass”.to “backack.FindFirstChildOfClass”

That doesn’t work, but i need to know if a player has in his hand (Active) a tool, not if a player has in the backpack (Inventory) the item.

here is the script:

local player = game:GetService("Players").LocalPlayer

local plr_backpack = player.Backpack
--

if plr_backpack:FindFirstChildOfClass("Tool") then
	print("has a item")
elseif not plr_backpack:FindFirstChildOfClass("Tool") then
	print("hasn't a item")
end

I think you can try doing a new variable that is named “equipped” or smth that is set to false and a tool path.

toolname.Equipped:Connect(function) -- Change "toolname" to anything you set as path
       equipped = true
end)

When tool is equipped

toolname.Unequipped:Connect(function) -- Change "toolname" to anything you set as path
       equipped = false
end)

When is unequipped

If equipped == true then
      print("has a item")
end

Add this at the end of script

Mh this should work, I will try this later.

local player = game:GetService("Players").LocalPlayer
	
local character = player.Character

for _, Tool in pairs(Character:GetChildren()) do
if Tool:IsA("Tool") then
print("Has a tool in hand")
end
end

or to check if a player has a specific tool in their hand

local player = game:GetService("Players").LocalPlayer
	
local character = player.Character
local YOURTOOL
for _, Tool in pairs(Character:GetChildren()) do
if Tool:IsA("Tool") and Tool == YOURTOOL  then
print("Has a tool in hand")
end
end

Solution my post if it works!

yes it definitely works, this was a simple solution! thanks anyway! The problem was that I located the player and character outside the function, so the for loop returned “nil”.

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