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
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
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
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”.