Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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)

2 comments

0

I'd already answered the question. ^

0

k

This discussion is preserved as it was. New answers, comments, and votes are closed.