Finding name of Child?

How do I find the name of the tool instead of the tool itself?

local inHand = hit.Parent:FindFirstChildWhichIsA(‘Tool’)
local inBackpack = player.Backpack:FindFirstChildWhichIsA(‘Tool’)

2 Likes

You can get the name of any instance by getting it’s Name property, e.g. tool.Name

2 Likes

Actually, I believe you could do something like:

local tool = (hit.Parent:FindFirstChildWhichIsA("Tool") or player.Backpack:FindFirstChildWhichIsA("Tool")) 
print(tool.Name)
4 Likes

Otherwise, :FindFirstChild("ToolName") would do the trick.

2 Likes

But he’s trying to find the tool’s name.

2 Likes

Oh, thought he wanted to get the tool by name, never mind.

1 Like

Thanks for all the great answers!

1 Like

I think you can do something like this

hit.Parent.ChildAdded:Connect(function()
    for _, child in pairs(hit.Parent:GetChildren()) do
        if child:IsA("Tool") then
            print(child.Name) 
        end
    end
end

Basically it detect if a ChildAdded in the hit.Parent and check every children inside hit.Parent and if it’s a tool print it’s name, I don’t think this is the best solution but I think it helps with what you need

3 Likes