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

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

Asked by 6 years ago

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

Log in to vote
0
Answered by 6 years ago

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
Ad

Answer this question