I wanted to call a function to see if there was a tool in the character. However, the function returns false even though I checked and the tool was in the character.
function checkforTool() for _,tool in ipairs(plr.Character:GetChildren()) do if tool:IsA("Tool") then return true else return false end end end
Don't worry about missing variables, I'm just trying to get to the point. Am I using the for loop correctly?
What is happening is, whenever that first object of Character is found out not to be a tool, the function will automatically return the false value.
Wait to return the false value at the end of the loop. That way you've gone through all objects and there are no tools detected.
function checkforTool() for _,tool in ipairs(plr.Character:GetChildren()) do if tool:IsA("Tool") then return true end end return false --All you had to do was move return false to outside the for loop. end