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)
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)
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)