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

how to...state if a tool is not found?

Hello!

Just scripting like the rest of you.

my question is, what would code be if a tool was not found in the player.character.

for i,v in pairs(player.Character:GetChildren()) do
	if v:IsA("Tool") then -- What would I put here to make it so if the Tool is not found in the character?

I'm super sure this is simple but it eludes me, thank you and appreciate it!~

1 answer

if you mean what to do if the item is not a tool then you just add an else or elseif statement onto the end like so

for i,v in pairs(player.Character:GetChildren()) do
    if v:IsA("Tool") then 
	--do this if it is a tool
    else
	--do this if not a tool
end

If you mean, what do you do if there are no tools found in the character then you can do this.

local toolFound = false --use this to determine if a tool was found

for i, v in pairs(player.Character:GetChildren()) do
	if v:IsA('Tool') then
		toolFound = true -- now we know we found a tool
end

print(toolFound) -- tells you if the tool is found or not

if toolFound == false then
	-- now we can do this if the tool wasnt found
end

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