Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Why doesn't my script find the tool in the player's character?

Asked by 4 years ago

I don't understand why this script doesn't work, when I click a textButton I want it to search through the player's character and find the tool (that is equipped) and print the name of the tool. However, nothing is being printed and I'm not sure why.

Code:

textButton.MouseButton1Click:Connect(function()
    local tool = character:FindFirstChild("Tool")
    if tool then

    end
end)


2 answers

Log in to vote
2
Answered by 4 years ago

I will answer my own question for people who are wanting further reference with the problem, I was making the mistake of using FindFirstChild, but instead of searching for the class of "Tool" it was searching for a specific name, which didn't meet the criteria. Instead, you have to use FindFirstChildWhichIsA instead, and instead of searching for a specific name it will search for the class of tool. This is my updated code:

textButton.MouseButton1Click:Connect(function()
    local tool = character:FindFirstChildWhichIsA("Tool")
    if tool then
        print(tool)
    else
        print("This player doeen't have a tool")
    end
end)


Ad
Log in to vote
0
Answered by 4 years ago

Try This! Please Accept My Answer If Its Working.

local player = game.Players.LocalPlayer

textButton.MouseButton1Click:Connect(function()
    if not player.Backpack:FindFirstChild("Tool") then
        print("this player doesn't have tool")
    else
        print("this player Already have tool!")
    end
end)
0
I'd already answered the question. ^ RyanTheLion911 195 — 4y
0
k ImAnonymousBan 24 — 4y

Answer this question